omnius 1.0.86 → 1.0.88
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 +1048 -77
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96453,7 +96453,7 @@ var require_md5 = __commonJS({
|
|
|
96453
96453
|
if (!_initialized) {
|
|
96454
96454
|
_init();
|
|
96455
96455
|
}
|
|
96456
|
-
var
|
|
96456
|
+
var _state4 = null;
|
|
96457
96457
|
var _input = forge.util.createBuffer();
|
|
96458
96458
|
var _w = new Array(16);
|
|
96459
96459
|
var md = {
|
|
@@ -96475,7 +96475,7 @@ var require_md5 = __commonJS({
|
|
|
96475
96475
|
md.fullMessageLength.push(0);
|
|
96476
96476
|
}
|
|
96477
96477
|
_input = forge.util.createBuffer();
|
|
96478
|
-
|
|
96478
|
+
_state4 = {
|
|
96479
96479
|
h0: 1732584193,
|
|
96480
96480
|
h1: 4023233417,
|
|
96481
96481
|
h2: 2562383102,
|
|
@@ -96498,7 +96498,7 @@ var require_md5 = __commonJS({
|
|
|
96498
96498
|
len[0] = len[1] / 4294967296 >>> 0;
|
|
96499
96499
|
}
|
|
96500
96500
|
_input.putBytes(msg);
|
|
96501
|
-
_update(
|
|
96501
|
+
_update(_state4, _w, _input);
|
|
96502
96502
|
if (_input.read > 2048 || _input.length() === 0) {
|
|
96503
96503
|
_input.compact();
|
|
96504
96504
|
}
|
|
@@ -96517,10 +96517,10 @@ var require_md5 = __commonJS({
|
|
|
96517
96517
|
finalBlock.putInt32Le(bits >>> 0);
|
|
96518
96518
|
}
|
|
96519
96519
|
var s2 = {
|
|
96520
|
-
h0:
|
|
96521
|
-
h1:
|
|
96522
|
-
h2:
|
|
96523
|
-
h3:
|
|
96520
|
+
h0: _state4.h0,
|
|
96521
|
+
h1: _state4.h1,
|
|
96522
|
+
h2: _state4.h2,
|
|
96523
|
+
h3: _state4.h3
|
|
96524
96524
|
};
|
|
96525
96525
|
_update(s2, _w, finalBlock);
|
|
96526
96526
|
var rval = forge.util.createBuffer();
|
|
@@ -97249,7 +97249,7 @@ var require_sha256 = __commonJS({
|
|
|
97249
97249
|
if (!_initialized) {
|
|
97250
97250
|
_init();
|
|
97251
97251
|
}
|
|
97252
|
-
var
|
|
97252
|
+
var _state4 = null;
|
|
97253
97253
|
var _input = forge.util.createBuffer();
|
|
97254
97254
|
var _w = new Array(64);
|
|
97255
97255
|
var md = {
|
|
@@ -97271,7 +97271,7 @@ var require_sha256 = __commonJS({
|
|
|
97271
97271
|
md.fullMessageLength.push(0);
|
|
97272
97272
|
}
|
|
97273
97273
|
_input = forge.util.createBuffer();
|
|
97274
|
-
|
|
97274
|
+
_state4 = {
|
|
97275
97275
|
h0: 1779033703,
|
|
97276
97276
|
h1: 3144134277,
|
|
97277
97277
|
h2: 1013904242,
|
|
@@ -97298,7 +97298,7 @@ var require_sha256 = __commonJS({
|
|
|
97298
97298
|
len[0] = len[1] / 4294967296 >>> 0;
|
|
97299
97299
|
}
|
|
97300
97300
|
_input.putBytes(msg);
|
|
97301
|
-
_update(
|
|
97301
|
+
_update(_state4, _w, _input);
|
|
97302
97302
|
if (_input.read > 2048 || _input.length() === 0) {
|
|
97303
97303
|
_input.compact();
|
|
97304
97304
|
}
|
|
@@ -97321,14 +97321,14 @@ var require_sha256 = __commonJS({
|
|
|
97321
97321
|
}
|
|
97322
97322
|
finalBlock.putInt32(bits);
|
|
97323
97323
|
var s2 = {
|
|
97324
|
-
h0:
|
|
97325
|
-
h1:
|
|
97326
|
-
h2:
|
|
97327
|
-
h3:
|
|
97328
|
-
h4:
|
|
97329
|
-
h5:
|
|
97330
|
-
h6:
|
|
97331
|
-
h7:
|
|
97324
|
+
h0: _state4.h0,
|
|
97325
|
+
h1: _state4.h1,
|
|
97326
|
+
h2: _state4.h2,
|
|
97327
|
+
h3: _state4.h3,
|
|
97328
|
+
h4: _state4.h4,
|
|
97329
|
+
h5: _state4.h5,
|
|
97330
|
+
h6: _state4.h6,
|
|
97331
|
+
h7: _state4.h7
|
|
97332
97332
|
};
|
|
97333
97333
|
_update(s2, _w, finalBlock);
|
|
97334
97334
|
var rval = forge.util.createBuffer();
|
|
@@ -99479,7 +99479,7 @@ var require_sha1 = __commonJS({
|
|
|
99479
99479
|
if (!_initialized) {
|
|
99480
99480
|
_init();
|
|
99481
99481
|
}
|
|
99482
|
-
var
|
|
99482
|
+
var _state4 = null;
|
|
99483
99483
|
var _input = forge.util.createBuffer();
|
|
99484
99484
|
var _w = new Array(80);
|
|
99485
99485
|
var md = {
|
|
@@ -99501,7 +99501,7 @@ var require_sha1 = __commonJS({
|
|
|
99501
99501
|
md.fullMessageLength.push(0);
|
|
99502
99502
|
}
|
|
99503
99503
|
_input = forge.util.createBuffer();
|
|
99504
|
-
|
|
99504
|
+
_state4 = {
|
|
99505
99505
|
h0: 1732584193,
|
|
99506
99506
|
h1: 4023233417,
|
|
99507
99507
|
h2: 2562383102,
|
|
@@ -99525,7 +99525,7 @@ var require_sha1 = __commonJS({
|
|
|
99525
99525
|
len[0] = len[1] / 4294967296 >>> 0;
|
|
99526
99526
|
}
|
|
99527
99527
|
_input.putBytes(msg);
|
|
99528
|
-
_update(
|
|
99528
|
+
_update(_state4, _w, _input);
|
|
99529
99529
|
if (_input.read > 2048 || _input.length() === 0) {
|
|
99530
99530
|
_input.compact();
|
|
99531
99531
|
}
|
|
@@ -99548,11 +99548,11 @@ var require_sha1 = __commonJS({
|
|
|
99548
99548
|
}
|
|
99549
99549
|
finalBlock.putInt32(bits);
|
|
99550
99550
|
var s2 = {
|
|
99551
|
-
h0:
|
|
99552
|
-
h1:
|
|
99553
|
-
h2:
|
|
99554
|
-
h3:
|
|
99555
|
-
h4:
|
|
99551
|
+
h0: _state4.h0,
|
|
99552
|
+
h1: _state4.h1,
|
|
99553
|
+
h2: _state4.h2,
|
|
99554
|
+
h3: _state4.h3,
|
|
99555
|
+
h4: _state4.h4
|
|
99556
99556
|
};
|
|
99557
99557
|
_update(s2, _w, finalBlock);
|
|
99558
99558
|
var rval = forge.util.createBuffer();
|
|
@@ -107678,7 +107678,7 @@ var require_sha512 = __commonJS({
|
|
|
107678
107678
|
if (!(algorithm in _states)) {
|
|
107679
107679
|
throw new Error("Invalid SHA-512 algorithm: " + algorithm);
|
|
107680
107680
|
}
|
|
107681
|
-
var
|
|
107681
|
+
var _state4 = _states[algorithm];
|
|
107682
107682
|
var _h = null;
|
|
107683
107683
|
var _input = forge.util.createBuffer();
|
|
107684
107684
|
var _w = new Array(80);
|
|
@@ -107717,9 +107717,9 @@ var require_sha512 = __commonJS({
|
|
|
107717
107717
|
md.fullMessageLength.push(0);
|
|
107718
107718
|
}
|
|
107719
107719
|
_input = forge.util.createBuffer();
|
|
107720
|
-
_h = new Array(
|
|
107721
|
-
for (var i2 = 0; i2 <
|
|
107722
|
-
_h[i2] =
|
|
107720
|
+
_h = new Array(_state4.length);
|
|
107721
|
+
for (var i2 = 0; i2 < _state4.length; ++i2) {
|
|
107722
|
+
_h[i2] = _state4[i2].slice(0);
|
|
107723
107723
|
}
|
|
107724
107724
|
return md;
|
|
107725
107725
|
};
|
|
@@ -282169,7 +282169,7 @@ ${lanes.join("\n")}
|
|
|
282169
282169
|
initial
|
|
282170
282170
|
);
|
|
282171
282171
|
}
|
|
282172
|
-
function appendCommentRange(pos, end, kind, hasTrailingNewLine,
|
|
282172
|
+
function appendCommentRange(pos, end, kind, hasTrailingNewLine, _state4, comments = []) {
|
|
282173
282173
|
comments.push({ kind, pos, end, hasTrailingNewLine });
|
|
282174
282174
|
return comments;
|
|
282175
282175
|
}
|
|
@@ -401925,7 +401925,7 @@ ${lanes.join("\n")}
|
|
|
401925
401925
|
function onLeft(next, _workArea, parent2) {
|
|
401926
401926
|
return maybeEmitExpression(next, parent2, "left");
|
|
401927
401927
|
}
|
|
401928
|
-
function onOperator(operatorToken,
|
|
401928
|
+
function onOperator(operatorToken, _state4, node) {
|
|
401929
401929
|
const isCommaOperator = operatorToken.kind !== 28;
|
|
401930
401930
|
const linesBeforeOperator = getLinesBetweenNodes(node, node.left, operatorToken);
|
|
401931
401931
|
const linesAfterOperator = getLinesBetweenNodes(node, operatorToken, node.right);
|
|
@@ -524973,7 +524973,7 @@ function resolveDefaultPoolConfig() {
|
|
|
524973
524973
|
const targetGpuInstances = Number(process.env["OMNIUS_OLLAMA_TARGET_GPU_INSTANCES"]) || 0;
|
|
524974
524974
|
const gpuPlacementRaw = (process.env["OMNIUS_OLLAMA_GPU_PLACEMENT"] ?? "auto").toLowerCase();
|
|
524975
524975
|
const gpuPlacement = gpuPlacementRaw === "dedicated" || gpuPlacementRaw === "elastic" || gpuPlacementRaw === "auto" ? gpuPlacementRaw : "auto";
|
|
524976
|
-
const idleMs = Number(process.env["OMNIUS_OLLAMA_IDLE_MS"]) ||
|
|
524976
|
+
const idleMs = Number(process.env["OMNIUS_OLLAMA_IDLE_MS"]) || 3 * 60 * 60 * 1e3;
|
|
524977
524977
|
const reaperIntervalMs = Number(process.env["OMNIUS_OLLAMA_REAPER_MS"]) || 3e4;
|
|
524978
524978
|
const spawnPortStart = Number(process.env["OMNIUS_OLLAMA_SPAWN_PORT"]) || 11435;
|
|
524979
524979
|
const sharedModelStore = discoverSystemOllamaModelStore();
|
|
@@ -525176,6 +525176,19 @@ var init_ollama_pool = __esm({
|
|
|
525176
525176
|
activePlacementMode = "constrained";
|
|
525177
525177
|
gpuCache = null;
|
|
525178
525178
|
slotWaiters = [];
|
|
525179
|
+
/**
|
|
525180
|
+
* Agent → preferred instance id. Set whenever an acquire resolves an
|
|
525181
|
+
* `agentId` to an instance. Lets two simultaneous sessions (e.g. two
|
|
525182
|
+
* Telegram chats) keep landing on different cards rather than re-racing
|
|
525183
|
+
* the scorer every turn. Trimmed when the referenced instance is reaped.
|
|
525184
|
+
*/
|
|
525185
|
+
affinityById = /* @__PURE__ */ new Map();
|
|
525186
|
+
/**
|
|
525187
|
+
* Recent agent ids per instance id (most-recent first, capped at 5).
|
|
525188
|
+
* Surfaced in status() so the TUI can show "instance X serves chats
|
|
525189
|
+
* A,B,C". Bound is small; this is a UX hint, not a routing primary.
|
|
525190
|
+
*/
|
|
525191
|
+
recentAgentsByInstance = /* @__PURE__ */ new Map();
|
|
525179
525192
|
constructor(config, opts) {
|
|
525180
525193
|
super();
|
|
525181
525194
|
this.config = { ...resolveDefaultPoolConfig(), ...config };
|
|
@@ -525194,10 +525207,50 @@ var init_ollama_pool = __esm({
|
|
|
525194
525207
|
lastUsedMs: Date.now(),
|
|
525195
525208
|
knownModels: /* @__PURE__ */ new Set(),
|
|
525196
525209
|
maxParallel: this.config.maxParallelPerInstance,
|
|
525197
|
-
totalRequests: 0
|
|
525210
|
+
totalRequests: 0,
|
|
525211
|
+
pid: null,
|
|
525212
|
+
spawnedAtMs: Date.now()
|
|
525198
525213
|
}, null));
|
|
525199
525214
|
this.startReaper();
|
|
525200
525215
|
}
|
|
525216
|
+
/**
|
|
525217
|
+
* Resolve the effective agent id for an acquire request. Explicit option
|
|
525218
|
+
* wins; otherwise consult the conventional env vars. Returns null when no
|
|
525219
|
+
* agent context is available so the scorer falls back to model affinity.
|
|
525220
|
+
*/
|
|
525221
|
+
resolveAgentId(opts) {
|
|
525222
|
+
if (opts.agentId && opts.agentId.trim())
|
|
525223
|
+
return opts.agentId.trim();
|
|
525224
|
+
const envAgent = process.env["OMNIUS_AGENT_ID"]?.trim();
|
|
525225
|
+
if (envAgent)
|
|
525226
|
+
return envAgent;
|
|
525227
|
+
const envSession = process.env["OMNIUS_SESSION_ID"]?.trim();
|
|
525228
|
+
if (envSession)
|
|
525229
|
+
return envSession;
|
|
525230
|
+
return null;
|
|
525231
|
+
}
|
|
525232
|
+
/**
|
|
525233
|
+
* Record that `agentId` was just routed to `instanceId`. Caps the per-
|
|
525234
|
+
* instance affinity hint list at 5 entries (LRU). Idempotent under
|
|
525235
|
+
* repeated record of the same pair.
|
|
525236
|
+
*/
|
|
525237
|
+
recordAffinity(agentId, instanceId) {
|
|
525238
|
+
this.affinityById.set(agentId, instanceId);
|
|
525239
|
+
const existing = this.recentAgentsByInstance.get(instanceId) ?? [];
|
|
525240
|
+
const filtered = existing.filter((a2) => a2 !== agentId);
|
|
525241
|
+
filtered.unshift(agentId);
|
|
525242
|
+
if (filtered.length > 5)
|
|
525243
|
+
filtered.length = 5;
|
|
525244
|
+
this.recentAgentsByInstance.set(instanceId, filtered);
|
|
525245
|
+
}
|
|
525246
|
+
/** Drop affinity entries pointing at a reaped instance so future acquires don't aim at a dead instance. */
|
|
525247
|
+
dropAffinityFor(instanceId) {
|
|
525248
|
+
for (const [agent, target] of this.affinityById) {
|
|
525249
|
+
if (target === instanceId)
|
|
525250
|
+
this.affinityById.delete(agent);
|
|
525251
|
+
}
|
|
525252
|
+
this.recentAgentsByInstance.delete(instanceId);
|
|
525253
|
+
}
|
|
525201
525254
|
/**
|
|
525202
525255
|
* Reserve a slot for one inference request. Returns immediately with a
|
|
525203
525256
|
* usable base URL, even when the pool has to spawn a fresh instance
|
|
@@ -525211,62 +525264,73 @@ var init_ollama_pool = __esm({
|
|
|
525211
525264
|
* 4. Queue at the pool boundary when all allowed lanes are busy.
|
|
525212
525265
|
*/
|
|
525213
525266
|
async acquire(opts) {
|
|
525267
|
+
const resolvedAgentId = this.resolveAgentId(opts);
|
|
525268
|
+
const optsWithAgent = resolvedAgentId ? { ...opts, agentId: resolvedAgentId } : opts;
|
|
525214
525269
|
const gpus = await this.getGpusForPlacement();
|
|
525215
525270
|
let placementMode = this.placementModeFor(gpus);
|
|
525216
525271
|
this.activePlacementMode = placementMode;
|
|
525217
525272
|
if (placementMode === "dedicated") {
|
|
525218
|
-
await this.ensureDedicatedGpuPool(
|
|
525273
|
+
await this.ensureDedicatedGpuPool(optsWithAgent.model, gpus);
|
|
525219
525274
|
if (!this.instances.some((i2) => i2.state.poolOwned)) {
|
|
525220
525275
|
placementMode = "constrained";
|
|
525221
525276
|
this.activePlacementMode = placementMode;
|
|
525222
525277
|
}
|
|
525223
525278
|
}
|
|
525224
|
-
const pick = this.pickInstance(
|
|
525279
|
+
const pick = this.pickInstance(optsWithAgent);
|
|
525225
525280
|
if (pick) {
|
|
525226
|
-
pick.acquire(
|
|
525227
|
-
|
|
525281
|
+
pick.acquire(optsWithAgent.model);
|
|
525282
|
+
if (resolvedAgentId)
|
|
525283
|
+
this.recordAffinity(resolvedAgentId, pick.state.id);
|
|
525284
|
+
return this.buildSlot(pick, resolvedAgentId);
|
|
525228
525285
|
}
|
|
525229
525286
|
if (placementMode === "constrained") {
|
|
525230
|
-
return this.acquireQueued(
|
|
525287
|
+
return this.acquireQueued(optsWithAgent, resolvedAgentId);
|
|
525231
525288
|
}
|
|
525232
|
-
const spawned = placementMode === "elastic" ? await this.maybeSpawnInstance(
|
|
525289
|
+
const spawned = placementMode === "elastic" ? await this.maybeSpawnInstance(optsWithAgent.model) : null;
|
|
525233
525290
|
if (spawned && !spawned.isSaturated()) {
|
|
525234
|
-
spawned.acquire(
|
|
525235
|
-
|
|
525291
|
+
spawned.acquire(optsWithAgent.model);
|
|
525292
|
+
if (resolvedAgentId)
|
|
525293
|
+
this.recordAffinity(resolvedAgentId, spawned.state.id);
|
|
525294
|
+
return this.buildSlot(spawned, resolvedAgentId);
|
|
525236
525295
|
}
|
|
525237
|
-
return this.acquireQueued(
|
|
525296
|
+
return this.acquireQueued(optsWithAgent, resolvedAgentId);
|
|
525238
525297
|
}
|
|
525239
525298
|
/** Synchronous routing decision; returns the instance or null if every one is saturated. */
|
|
525240
525299
|
pickInstance(opts) {
|
|
525241
525300
|
const candidates = this.instances.filter((inst) => !this.isEffectivelySaturated(inst) && !(this.activePlacementMode === "dedicated" && this.dedicatedGpuPoolActive && !inst.state.poolOwned && !opts.preferBaseInstance));
|
|
525242
525301
|
if (candidates.length === 0)
|
|
525243
525302
|
return null;
|
|
525303
|
+
const affinityTargetId = opts.agentId ? this.affinityById.get(opts.agentId) : void 0;
|
|
525244
525304
|
const scored = candidates.map((inst) => ({
|
|
525245
525305
|
inst,
|
|
525246
|
-
score: (inst.state.knownModels.has(opts.model) ? 100 : 0) + (opts.preferBaseInstance && !inst.state.poolOwned ? 25 : 0) + this.effectiveFreeSlots(inst) * 10 - inst.state.inflight
|
|
525306
|
+
score: (inst.state.knownModels.has(opts.model) ? 100 : 0) + (affinityTargetId && inst.state.id === affinityTargetId ? 60 : 0) + (opts.preferBaseInstance && !inst.state.poolOwned ? 25 : 0) + this.effectiveFreeSlots(inst) * 10 - inst.state.inflight
|
|
525247
525307
|
}));
|
|
525248
525308
|
scored.sort((a2, b) => b.score - a2.score);
|
|
525249
525309
|
return scored[0].inst;
|
|
525250
525310
|
}
|
|
525251
|
-
buildSlot(inst) {
|
|
525311
|
+
buildSlot(inst, agentId) {
|
|
525252
525312
|
return {
|
|
525253
525313
|
instanceId: inst.state.id,
|
|
525254
525314
|
baseUrl: inst.state.baseUrl,
|
|
525255
525315
|
poolOwned: inst.state.poolOwned,
|
|
525256
525316
|
gpuUuid: inst.state.gpuUuid,
|
|
525257
525317
|
gpuIndex: inst.state.gpuIndex,
|
|
525318
|
+
pid: inst.state.pid,
|
|
525319
|
+
agentId,
|
|
525258
525320
|
release: (success) => {
|
|
525259
525321
|
inst.release(success);
|
|
525260
525322
|
this.wakeNextSlotWaiter();
|
|
525261
525323
|
}
|
|
525262
525324
|
};
|
|
525263
525325
|
}
|
|
525264
|
-
async acquireQueued(opts) {
|
|
525326
|
+
async acquireQueued(opts, agentId) {
|
|
525265
525327
|
for (; ; ) {
|
|
525266
525328
|
const pick = this.pickInstance(opts);
|
|
525267
525329
|
if (pick) {
|
|
525268
525330
|
pick.acquire(opts.model);
|
|
525269
|
-
|
|
525331
|
+
if (agentId)
|
|
525332
|
+
this.recordAffinity(agentId, pick.state.id);
|
|
525333
|
+
return this.buildSlot(pick, agentId);
|
|
525270
525334
|
}
|
|
525271
525335
|
await new Promise((resolve52) => this.slotWaiters.push(resolve52));
|
|
525272
525336
|
}
|
|
@@ -525409,6 +525473,7 @@ var init_ollama_pool = __esm({
|
|
|
525409
525473
|
this.emit("spawn-failed", { port, gpuUuid, gpuIndex, error: err });
|
|
525410
525474
|
return null;
|
|
525411
525475
|
}
|
|
525476
|
+
const spawnedAtMs = Date.now();
|
|
525412
525477
|
const inst = new OllamaInstance({
|
|
525413
525478
|
id: `omnius-ollama-${port}`,
|
|
525414
525479
|
baseUrl: `http://127.0.0.1:${port}`,
|
|
@@ -525418,13 +525483,29 @@ var init_ollama_pool = __esm({
|
|
|
525418
525483
|
poolOwned: true,
|
|
525419
525484
|
inflight: 0,
|
|
525420
525485
|
peakInflight: 0,
|
|
525421
|
-
lastUsedMs:
|
|
525486
|
+
lastUsedMs: spawnedAtMs,
|
|
525422
525487
|
knownModels: /* @__PURE__ */ new Set([model]),
|
|
525423
525488
|
maxParallel: this.config.maxParallelPerInstance,
|
|
525424
|
-
totalRequests: 0
|
|
525489
|
+
totalRequests: 0,
|
|
525490
|
+
pid: proc.pid,
|
|
525491
|
+
spawnedAtMs
|
|
525425
525492
|
}, proc);
|
|
525426
525493
|
this.instances.push(inst);
|
|
525427
|
-
this.emit("instance-spawned", {
|
|
525494
|
+
this.emit("instance-spawned", {
|
|
525495
|
+
id: inst.state.id,
|
|
525496
|
+
pid: proc.pid,
|
|
525497
|
+
port,
|
|
525498
|
+
gpuUuid,
|
|
525499
|
+
gpuIndex,
|
|
525500
|
+
model,
|
|
525501
|
+
spawnedAtMs,
|
|
525502
|
+
provenance: {
|
|
525503
|
+
entity: `urn:omnius:ollama-instance:${inst.state.id}`,
|
|
525504
|
+
activity: "ollama-instance-spawn",
|
|
525505
|
+
agent: "orchestrator.ollama-pool",
|
|
525506
|
+
timestampMs: spawnedAtMs
|
|
525507
|
+
}
|
|
525508
|
+
});
|
|
525428
525509
|
return inst;
|
|
525429
525510
|
}
|
|
525430
525511
|
/**
|
|
@@ -525464,11 +525545,22 @@ var init_ollama_pool = __esm({
|
|
|
525464
525545
|
continue;
|
|
525465
525546
|
}
|
|
525466
525547
|
if (inst.isIdleLongerThan(this.config.idleMs)) {
|
|
525548
|
+
const reapedAtMs = Date.now();
|
|
525467
525549
|
await inst.terminate();
|
|
525550
|
+
this.dropAffinityFor(inst.state.id);
|
|
525468
525551
|
this.emit("instance-reaped", {
|
|
525469
525552
|
id: inst.state.id,
|
|
525553
|
+
pid: inst.state.pid,
|
|
525470
525554
|
totalRequests: inst.state.totalRequests,
|
|
525471
|
-
peakInflight: inst.state.peakInflight
|
|
525555
|
+
peakInflight: inst.state.peakInflight,
|
|
525556
|
+
ageMs: reapedAtMs - inst.state.spawnedAtMs,
|
|
525557
|
+
idleMs: reapedAtMs - inst.state.lastUsedMs,
|
|
525558
|
+
provenance: {
|
|
525559
|
+
entity: `urn:omnius:ollama-instance:${inst.state.id}`,
|
|
525560
|
+
activity: "ollama-instance-reap",
|
|
525561
|
+
agent: "orchestrator.ollama-pool",
|
|
525562
|
+
timestampMs: reapedAtMs
|
|
525563
|
+
}
|
|
525472
525564
|
});
|
|
525473
525565
|
continue;
|
|
525474
525566
|
}
|
|
@@ -525506,6 +525598,9 @@ var init_ollama_pool = __esm({
|
|
|
525506
525598
|
poolOwned: inst.state.poolOwned,
|
|
525507
525599
|
gpuUuid: inst.state.gpuUuid,
|
|
525508
525600
|
gpuIndex: inst.state.gpuIndex,
|
|
525601
|
+
pid: inst.state.pid,
|
|
525602
|
+
ageMs: Date.now() - inst.state.spawnedAtMs,
|
|
525603
|
+
affinityAgentIds: this.recentAgentsByInstance.get(inst.state.id) ?? [],
|
|
525509
525604
|
inflight: inst.state.inflight,
|
|
525510
525605
|
peakInflight: inst.state.peakInflight,
|
|
525511
525606
|
maxParallel: inst.state.maxParallel,
|
|
@@ -570015,6 +570110,9 @@ async function collectOllamaPoolMetrics() {
|
|
|
570015
570110
|
poolOwned: inst.poolOwned,
|
|
570016
570111
|
gpuUuid: inst.gpuUuid,
|
|
570017
570112
|
gpuIndex: inst.gpuIndex,
|
|
570113
|
+
pid: inst.pid,
|
|
570114
|
+
ageMs: inst.ageMs,
|
|
570115
|
+
affinityAgentIds: inst.affinityAgentIds,
|
|
570018
570116
|
inflight: inst.inflight,
|
|
570019
570117
|
maxParallel: inst.maxParallel,
|
|
570020
570118
|
totalRequests: inst.totalRequests
|
|
@@ -571046,6 +571144,12 @@ __export(status_bar_exports, {
|
|
|
571046
571144
|
unlockFooterRedraws: () => unlockFooterRedraws
|
|
571047
571145
|
});
|
|
571048
571146
|
import { readFileSync as readFileSync72 } from "node:fs";
|
|
571147
|
+
function formatPoolAge(ms) {
|
|
571148
|
+
if (ms < 6e4) return `${Math.max(0, Math.floor(ms / 1e3))}s`;
|
|
571149
|
+
if (ms < 60 * 6e4) return `${Math.floor(ms / 6e4)}m`;
|
|
571150
|
+
if (ms < 24 * 60 * 6e4) return `${Math.floor(ms / (60 * 6e4))}h`;
|
|
571151
|
+
return `${Math.floor(ms / (24 * 60 * 6e4))}d`;
|
|
571152
|
+
}
|
|
571049
571153
|
function lockFooterRedraws() {
|
|
571050
571154
|
_globalFooterLock = true;
|
|
571051
571155
|
}
|
|
@@ -571170,16 +571274,22 @@ var init_status_bar = __esm({
|
|
|
571170
571274
|
/** Timestamp when current task started (0 = no active task) */
|
|
571171
571275
|
taskStartMs = 0;
|
|
571172
571276
|
/** Number of tool calls in current session */
|
|
571173
|
-
|
|
571277
|
+
_toolCalls = 0;
|
|
571278
|
+
get toolCalls() {
|
|
571279
|
+
return this._toolCalls;
|
|
571280
|
+
}
|
|
571174
571281
|
/** Number of turns in current session */
|
|
571175
|
-
|
|
571282
|
+
_turns = 0;
|
|
571283
|
+
get turns() {
|
|
571284
|
+
return this._turns;
|
|
571285
|
+
}
|
|
571176
571286
|
/** Accumulated reading time in seconds (subset of humanTimeS) */
|
|
571177
571287
|
readingTimeS = 0;
|
|
571178
571288
|
/** Record a tool call — adds the expert baseline time */
|
|
571179
571289
|
recordToolCall(toolName) {
|
|
571180
571290
|
const baseline2 = EXPERT_TOOL_BASELINES[toolName] ?? DEFAULT_TOOL_BASELINE;
|
|
571181
571291
|
this.humanTimeS += baseline2 + CONTEXT_SWITCH_OVERHEAD;
|
|
571182
|
-
this.
|
|
571292
|
+
this._toolCalls++;
|
|
571183
571293
|
}
|
|
571184
571294
|
/**
|
|
571185
571295
|
* Record a tool result — adds human reading time based on content volume.
|
|
@@ -571203,7 +571313,7 @@ var init_status_bar = __esm({
|
|
|
571203
571313
|
/** Record a turn (assistant reasoning cycle) */
|
|
571204
571314
|
recordTurn() {
|
|
571205
571315
|
this.humanTimeS += TURN_PLANNING_OVERHEAD;
|
|
571206
|
-
this.
|
|
571316
|
+
this._turns++;
|
|
571207
571317
|
}
|
|
571208
571318
|
/** Mark the start of a task (for wall-clock tracking) */
|
|
571209
571319
|
taskStart() {
|
|
@@ -571258,6 +571368,21 @@ var init_status_bar = __esm({
|
|
|
571258
571368
|
lastCompletionTokens: 0,
|
|
571259
571369
|
contextWindowSize: 0
|
|
571260
571370
|
};
|
|
571371
|
+
// ── Metrics tracking for Telegram stats ──
|
|
571372
|
+
_backend = "ollama";
|
|
571373
|
+
_inferenceCount = 0;
|
|
571374
|
+
_totalInferenceDurationMs = 0;
|
|
571375
|
+
_peakTokensPerSecond = 0;
|
|
571376
|
+
_successfulToolCalls = 0;
|
|
571377
|
+
_failedToolCalls = 0;
|
|
571378
|
+
_toolCallBreakdown = [];
|
|
571379
|
+
_compactionCount = 0;
|
|
571380
|
+
_sessionStartAt = 0;
|
|
571381
|
+
_gpuName = "";
|
|
571382
|
+
_vramTotal = 0;
|
|
571383
|
+
_vramUsed = 0;
|
|
571384
|
+
_toolCalls = 0;
|
|
571385
|
+
_turns = 0;
|
|
571261
571386
|
active = false;
|
|
571262
571387
|
scrollRegionTop = 1;
|
|
571263
571388
|
// ── Agent View Multiplexing (WO-NA1) ──
|
|
@@ -571528,6 +571653,7 @@ var init_status_bar = __esm({
|
|
|
571528
571653
|
}
|
|
571529
571654
|
setHeaderIdentity(modelName, backendType, backendUrl2) {
|
|
571530
571655
|
this._modelName = modelName;
|
|
571656
|
+
this._backend = backendType || "ollama";
|
|
571531
571657
|
this._headerBackendType = backendType;
|
|
571532
571658
|
this._headerBackendUrl = backendUrl2;
|
|
571533
571659
|
this.refreshHeaderAndFooter();
|
|
@@ -572149,6 +572275,9 @@ var init_status_bar = __esm({
|
|
|
572149
572275
|
if (!this._metricsCollector.isActive || this._metricsCollector.source !== "remote") {
|
|
572150
572276
|
this._metricsCollector.startRemote((m2) => {
|
|
572151
572277
|
this._unifiedMetrics = m2;
|
|
572278
|
+
this._gpuName = m2.gpuName || "";
|
|
572279
|
+
this._vramTotal = m2.vramTotalMB || 0;
|
|
572280
|
+
this._vramUsed = m2.vramUsedMB || 0;
|
|
572152
572281
|
if (this.active) this.renderFooterPreserveCursor();
|
|
572153
572282
|
});
|
|
572154
572283
|
}
|
|
@@ -573963,11 +574092,18 @@ ${CONTENT_BG_SEQ}`);
|
|
|
573963
574092
|
const target = pool3.targetGpuInstances;
|
|
573964
574093
|
const poolColor = pool3.mode === "constrained" ? c3.yellow : target > 0 && ready < target ? c3.yellow : c3.green;
|
|
573965
574094
|
const poolDetail = pool3.mode === "constrained" ? "queue" : `${ready}/${target}`;
|
|
573966
|
-
const
|
|
574095
|
+
const poolOwned = pool3.instances.filter((i2) => i2.poolOwned);
|
|
574096
|
+
const pidSummary = poolOwned.length === 0 ? "" : ` PID[${poolOwned.map((i2) => `${i2.pid}@${i2.gpuIndex ?? "?"}`).slice(0, 3).join(",")}]`;
|
|
574097
|
+
const oldestAgeMs = poolOwned.reduce(
|
|
574098
|
+
(max, i2) => i2.ageMs > max ? i2.ageMs : max,
|
|
574099
|
+
0
|
|
574100
|
+
);
|
|
574101
|
+
const ageSummary = oldestAgeMs > 0 ? ` age=${formatPoolAge(oldestAgeMs)}` : "";
|
|
574102
|
+
const poolText = ` OLLAMA ${poolColor(`${pool3.mode}:${poolDetail}`)}${c3.dim(pidSummary)}${c3.dim(ageSummary)}`;
|
|
573967
574103
|
const compactText = ` OLLAMA ${poolColor(pool3.mode === "constrained" ? "queue" : `${ready}/${target}`)}`;
|
|
573968
574104
|
hwExpStr += poolText;
|
|
573969
574105
|
hwCompStr += compactText;
|
|
573970
|
-
hwExpW += 8 + `${pool3.mode}:${poolDetail}`.length;
|
|
574106
|
+
hwExpW += 8 + `${pool3.mode}:${poolDetail}`.length + pidSummary.length + ageSummary.length;
|
|
573971
574107
|
hwCompW += 8 + (pool3.mode === "constrained" ? "queue".length : `${ready}/${target}`.length);
|
|
573972
574108
|
}
|
|
573973
574109
|
if (!isLocal && hwExpW === 0) {
|
|
@@ -574735,6 +574871,86 @@ ${CONTENT_BG_SEQ}`);
|
|
|
574735
574871
|
}
|
|
574736
574872
|
});
|
|
574737
574873
|
}
|
|
574874
|
+
/** Record a tool result success/fail for metrics tracking. */
|
|
574875
|
+
recordToolSuccessFail(toolName, success) {
|
|
574876
|
+
if (success) {
|
|
574877
|
+
this._successfulToolCalls++;
|
|
574878
|
+
} else {
|
|
574879
|
+
this._failedToolCalls++;
|
|
574880
|
+
}
|
|
574881
|
+
const existing = this._toolCallBreakdown.find((t2) => t2.name === toolName);
|
|
574882
|
+
if (existing) {
|
|
574883
|
+
existing.count++;
|
|
574884
|
+
} else {
|
|
574885
|
+
this._toolCallBreakdown.push({ name: toolName, count: 1 });
|
|
574886
|
+
}
|
|
574887
|
+
}
|
|
574888
|
+
/** Record an inference completion for metrics tracking. */
|
|
574889
|
+
recordInference(durationMs, tokensPerSecond) {
|
|
574890
|
+
this._inferenceCount++;
|
|
574891
|
+
this._totalInferenceDurationMs += durationMs;
|
|
574892
|
+
if (tokensPerSecond > this._peakTokensPerSecond) {
|
|
574893
|
+
this._peakTokensPerSecond = tokensPerSecond;
|
|
574894
|
+
}
|
|
574895
|
+
if (this._sessionStartAt === 0) {
|
|
574896
|
+
this._sessionStartAt = Date.now();
|
|
574897
|
+
}
|
|
574898
|
+
}
|
|
574899
|
+
/** Record a compaction event for metrics tracking. */
|
|
574900
|
+
recordCompaction() {
|
|
574901
|
+
this._compactionCount++;
|
|
574902
|
+
}
|
|
574903
|
+
/** Set the model name for metrics tracking. */
|
|
574904
|
+
setModelNameForMetrics(name10) {
|
|
574905
|
+
this._modelName = name10;
|
|
574906
|
+
}
|
|
574907
|
+
/** Set the backend type for metrics tracking. */
|
|
574908
|
+
setBackendForMetrics(backend) {
|
|
574909
|
+
this._backend = backend;
|
|
574910
|
+
}
|
|
574911
|
+
/** Increment turn count. */
|
|
574912
|
+
incrementTurnCount() {
|
|
574913
|
+
this._turns++;
|
|
574914
|
+
}
|
|
574915
|
+
/** Increment tool call count. */
|
|
574916
|
+
incrementToolCallCount() {
|
|
574917
|
+
this._toolCalls++;
|
|
574918
|
+
}
|
|
574919
|
+
/** Return a snapshot of current metrics for the Telegram stats menu. */
|
|
574920
|
+
getMetricsSnapshot() {
|
|
574921
|
+
const m2 = this.metrics;
|
|
574922
|
+
const now = Date.now();
|
|
574923
|
+
const duration = this._sessionStartAt > 0 ? now - this._sessionStartAt : 0;
|
|
574924
|
+
const avgSpeed = duration > 0 ? m2.totalTokens / (duration / 1e3) : 0;
|
|
574925
|
+
const ctxPct = m2.contextWindowSize > 0 ? m2.estimatedContextTokens / m2.contextWindowSize * 100 : 0;
|
|
574926
|
+
return {
|
|
574927
|
+
model: this._modelName || "unknown",
|
|
574928
|
+
backend: this._backend || "ollama",
|
|
574929
|
+
totalInferences: this._inferenceCount,
|
|
574930
|
+
totalPromptTokens: m2.promptTokens,
|
|
574931
|
+
totalCompletionTokens: m2.completionTokens,
|
|
574932
|
+
totalTokens: m2.totalTokens,
|
|
574933
|
+
avgTokensPerSecond: avgSpeed,
|
|
574934
|
+
peakTokensPerSecond: this._peakTokensPerSecond,
|
|
574935
|
+
avgInferenceDurationMs: this._inferenceCount > 0 ? this._totalInferenceDurationMs / this._inferenceCount : 0,
|
|
574936
|
+
totalInferenceDurationMs: this._totalInferenceDurationMs,
|
|
574937
|
+
totalToolCalls: this._toolCalls,
|
|
574938
|
+
successfulToolCalls: this._successfulToolCalls,
|
|
574939
|
+
failedToolCalls: this._failedToolCalls,
|
|
574940
|
+
toolCallBreakdown: this._toolCallBreakdown.map((t2) => ({ name: t2.name, count: t2.count, avgDurationMs: 0 })),
|
|
574941
|
+
contextWindowSize: m2.contextWindowSize,
|
|
574942
|
+
estimatedContextTokens: m2.estimatedContextTokens,
|
|
574943
|
+
peakContextTokens: m2.estimatedContextTokens,
|
|
574944
|
+
contextUtilizationPct: ctxPct,
|
|
574945
|
+
compactionCount: this._compactionCount,
|
|
574946
|
+
sessionStartAt: this._sessionStartAt || now,
|
|
574947
|
+
sessionDurationMs: duration,
|
|
574948
|
+
turnCount: this._turns,
|
|
574949
|
+
gpuName: this._gpuName || null,
|
|
574950
|
+
gpuVramTotalMb: this._vramTotal || null,
|
|
574951
|
+
gpuVramUsedMb: this._vramUsed || null
|
|
574952
|
+
};
|
|
574953
|
+
}
|
|
574738
574954
|
};
|
|
574739
574955
|
}
|
|
574740
574956
|
});
|
|
@@ -603186,30 +603402,200 @@ var init_carousel_descriptors = __esm({
|
|
|
603186
603402
|
}
|
|
603187
603403
|
});
|
|
603188
603404
|
|
|
603405
|
+
// packages/cli/src/tui/syntax-highlight.ts
|
|
603406
|
+
var syntax_highlight_exports = {};
|
|
603407
|
+
__export(syntax_highlight_exports, {
|
|
603408
|
+
detectLanguage: () => detectLanguage2,
|
|
603409
|
+
getHighlightStatus: () => getHighlightStatus,
|
|
603410
|
+
highlightBlock: () => highlightBlock,
|
|
603411
|
+
highlightCode: () => highlightCode,
|
|
603412
|
+
isAvailable: () => isAvailable,
|
|
603413
|
+
prewarm: () => prewarm
|
|
603414
|
+
});
|
|
603415
|
+
function highlightingDisabled() {
|
|
603416
|
+
return !isTTY8 || noColorEnv || disableEnv;
|
|
603417
|
+
}
|
|
603418
|
+
async function loadHighlighter() {
|
|
603419
|
+
if (_state2.attempted) return _state2.fn;
|
|
603420
|
+
_state2.attempted = true;
|
|
603421
|
+
if (highlightingDisabled()) {
|
|
603422
|
+
_state2.reason = !isTTY8 ? "non-tty" : noColorEnv ? "NO_COLOR set" : "OMNIUS_TUI_HIGHLIGHT=0";
|
|
603423
|
+
return null;
|
|
603424
|
+
}
|
|
603425
|
+
try {
|
|
603426
|
+
const { createRequire: createRequire10 } = await import("node:module");
|
|
603427
|
+
const req2 = createRequire10(import.meta.url);
|
|
603428
|
+
let resolved = null;
|
|
603429
|
+
try {
|
|
603430
|
+
resolved = req2.resolve("cli-highlight");
|
|
603431
|
+
} catch {
|
|
603432
|
+
_state2.reason = "cli-highlight not installed";
|
|
603433
|
+
return null;
|
|
603434
|
+
}
|
|
603435
|
+
const mod2 = await import(resolved).catch(() => null);
|
|
603436
|
+
if (!mod2) {
|
|
603437
|
+
_state2.reason = "cli-highlight failed to load";
|
|
603438
|
+
return null;
|
|
603439
|
+
}
|
|
603440
|
+
const m2 = mod2;
|
|
603441
|
+
const candidate = m2.highlight ?? m2.default ?? null;
|
|
603442
|
+
if (typeof candidate !== "function") {
|
|
603443
|
+
_state2.reason = "cli-highlight export shape unrecognized";
|
|
603444
|
+
return null;
|
|
603445
|
+
}
|
|
603446
|
+
_state2.fn = candidate;
|
|
603447
|
+
return candidate;
|
|
603448
|
+
} catch (err) {
|
|
603449
|
+
_state2.reason = `import threw: ${err?.message ?? String(err)}`;
|
|
603450
|
+
return null;
|
|
603451
|
+
}
|
|
603452
|
+
}
|
|
603453
|
+
function loadHighlighterSync() {
|
|
603454
|
+
if (highlightingDisabled()) return null;
|
|
603455
|
+
return _state2.fn;
|
|
603456
|
+
}
|
|
603457
|
+
async function prewarm() {
|
|
603458
|
+
await loadHighlighter();
|
|
603459
|
+
}
|
|
603460
|
+
function isAvailable() {
|
|
603461
|
+
if (highlightingDisabled()) return false;
|
|
603462
|
+
return _state2.attempted && _state2.fn !== null;
|
|
603463
|
+
}
|
|
603464
|
+
function getHighlightStatus() {
|
|
603465
|
+
return {
|
|
603466
|
+
available: isAvailable(),
|
|
603467
|
+
attempted: _state2.attempted,
|
|
603468
|
+
reason: _state2.reason,
|
|
603469
|
+
isTTY: isTTY8,
|
|
603470
|
+
noColor: noColorEnv,
|
|
603471
|
+
disabledByEnv: disableEnv
|
|
603472
|
+
};
|
|
603473
|
+
}
|
|
603474
|
+
function highlightCode(code8, language) {
|
|
603475
|
+
if (!code8) return code8;
|
|
603476
|
+
const fn = loadHighlighterSync();
|
|
603477
|
+
if (!fn) return code8;
|
|
603478
|
+
const lang = (language ?? detectLanguage2(code8) ?? "").trim();
|
|
603479
|
+
try {
|
|
603480
|
+
if (lang) {
|
|
603481
|
+
return fn(code8, { language: lang, ignoreIllegals: true });
|
|
603482
|
+
}
|
|
603483
|
+
return fn(code8, { ignoreIllegals: true });
|
|
603484
|
+
} catch {
|
|
603485
|
+
return code8;
|
|
603486
|
+
}
|
|
603487
|
+
}
|
|
603488
|
+
function detectLanguage2(text) {
|
|
603489
|
+
if (!text) return null;
|
|
603490
|
+
const trimmed = text.trimStart();
|
|
603491
|
+
const shebang = trimmed.match(/^#!\s*\/[^\n]+/);
|
|
603492
|
+
if (shebang) {
|
|
603493
|
+
const sb = shebang[0];
|
|
603494
|
+
if (/python/.test(sb)) return "python";
|
|
603495
|
+
if (/(?:^|[\s/])(?:bash|sh|zsh)\b/.test(sb)) return "bash";
|
|
603496
|
+
if (/node/.test(sb)) return "javascript";
|
|
603497
|
+
if (/ruby/.test(sb)) return "ruby";
|
|
603498
|
+
if (/perl/.test(sb)) return "perl";
|
|
603499
|
+
}
|
|
603500
|
+
if (/^[\s\n]*[{[]/.test(trimmed)) {
|
|
603501
|
+
try {
|
|
603502
|
+
JSON.parse(trimmed);
|
|
603503
|
+
return "json";
|
|
603504
|
+
} catch {
|
|
603505
|
+
}
|
|
603506
|
+
}
|
|
603507
|
+
if (/^[-a-zA-Z_][\w-]*:\s/.test(trimmed) && /\n[-a-zA-Z_][\w-]*:\s/.test(trimmed)) {
|
|
603508
|
+
return "yaml";
|
|
603509
|
+
}
|
|
603510
|
+
if (/^(?:async def |def |class |import |from )/.test(trimmed) && /(?::\s*$|->|self\b)/m.test(trimmed)) {
|
|
603511
|
+
return "python";
|
|
603512
|
+
}
|
|
603513
|
+
if (/^(?:import |export |const |let |var |function |class |interface |type |async )/.test(trimmed)) {
|
|
603514
|
+
if (/(:\s*(?:string|number|boolean|any|unknown|void)\b|\binterface\b|\btype\s+\w+\s*=)/.test(trimmed)) {
|
|
603515
|
+
return "typescript";
|
|
603516
|
+
}
|
|
603517
|
+
return "javascript";
|
|
603518
|
+
}
|
|
603519
|
+
if (/(?:^|\n)\s*(?:fn |use |let mut |impl |struct |enum |trait )/.test(trimmed)) {
|
|
603520
|
+
return "rust";
|
|
603521
|
+
}
|
|
603522
|
+
if (/(?:^package \w+|\nfunc \w+\s*\()/.test(trimmed)) {
|
|
603523
|
+
return "go";
|
|
603524
|
+
}
|
|
603525
|
+
if (/^\s*(?:SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP)\b/i.test(trimmed)) {
|
|
603526
|
+
return "sql";
|
|
603527
|
+
}
|
|
603528
|
+
if (/^[\s\n]*<(?:!DOCTYPE|html|\?xml|\w+)/i.test(trimmed)) {
|
|
603529
|
+
return "html";
|
|
603530
|
+
}
|
|
603531
|
+
if (/^(?:---|\+\+\+|@@|diff )/.test(trimmed)) {
|
|
603532
|
+
return "diff";
|
|
603533
|
+
}
|
|
603534
|
+
if (/^\s*(?:\$\s|sudo |apt |brew |npm |pnpm |yarn |git |docker |kubectl |curl |wget )/.test(trimmed)) {
|
|
603535
|
+
return "bash";
|
|
603536
|
+
}
|
|
603537
|
+
return null;
|
|
603538
|
+
}
|
|
603539
|
+
function highlightBlock(code8, language) {
|
|
603540
|
+
if (!code8) return [""];
|
|
603541
|
+
const fn = loadHighlighterSync();
|
|
603542
|
+
if (!fn) return code8.split("\n");
|
|
603543
|
+
const lang = (language ?? detectLanguage2(code8) ?? "").trim();
|
|
603544
|
+
try {
|
|
603545
|
+
const out = lang ? fn(code8, { language: lang, ignoreIllegals: true }) : fn(code8, { ignoreIllegals: true });
|
|
603546
|
+
const lines = out.split("\n");
|
|
603547
|
+
const inputLines = code8.split("\n");
|
|
603548
|
+
if (lines.length === inputLines.length) return lines;
|
|
603549
|
+
if (lines.length < inputLines.length) {
|
|
603550
|
+
while (lines.length < inputLines.length) lines.push("");
|
|
603551
|
+
} else {
|
|
603552
|
+
lines.length = inputLines.length;
|
|
603553
|
+
}
|
|
603554
|
+
return lines;
|
|
603555
|
+
} catch {
|
|
603556
|
+
return code8.split("\n");
|
|
603557
|
+
}
|
|
603558
|
+
}
|
|
603559
|
+
var isTTY8, noColorEnv, disableEnv, _state2;
|
|
603560
|
+
var init_syntax_highlight = __esm({
|
|
603561
|
+
"packages/cli/src/tui/syntax-highlight.ts"() {
|
|
603562
|
+
"use strict";
|
|
603563
|
+
isTTY8 = process.stdout?.isTTY ?? false;
|
|
603564
|
+
noColorEnv = process.env["NO_COLOR"] !== void 0 && process.env["NO_COLOR"] !== "";
|
|
603565
|
+
disableEnv = process.env["OMNIUS_TUI_HIGHLIGHT"] === "0";
|
|
603566
|
+
_state2 = {
|
|
603567
|
+
attempted: false,
|
|
603568
|
+
fn: null,
|
|
603569
|
+
reason: ""
|
|
603570
|
+
};
|
|
603571
|
+
}
|
|
603572
|
+
});
|
|
603573
|
+
|
|
603189
603574
|
// packages/cli/src/tui/stream-renderer.ts
|
|
603190
603575
|
function fg2564(code8, text) {
|
|
603191
|
-
return
|
|
603576
|
+
return isTTY9 ? `\x1B[38;5;${code8}m${text}\x1B[0m` : text;
|
|
603192
603577
|
}
|
|
603193
603578
|
function dimText(text) {
|
|
603194
|
-
return
|
|
603579
|
+
return isTTY9 ? `\x1B[38;5;${tuiTextDim()}m${text}\x1B[0m` : text;
|
|
603195
603580
|
}
|
|
603196
603581
|
function italicText(text) {
|
|
603197
|
-
return
|
|
603582
|
+
return isTTY9 ? `\x1B[3m${text}\x1B[0m` : text;
|
|
603198
603583
|
}
|
|
603199
603584
|
function dimItalic(text) {
|
|
603200
|
-
return
|
|
603585
|
+
return isTTY9 ? `\x1B[3m\x1B[38;5;${tuiTextDim()}m${text}\x1B[0m` : text;
|
|
603201
603586
|
}
|
|
603202
603587
|
function boldText(text) {
|
|
603203
|
-
return
|
|
603588
|
+
return isTTY9 ? `\x1B[1m${text}\x1B[0m` : text;
|
|
603204
603589
|
}
|
|
603205
|
-
var
|
|
603590
|
+
var isTTY9, PASTEL, StreamRenderer;
|
|
603206
603591
|
var init_stream_renderer = __esm({
|
|
603207
603592
|
"packages/cli/src/tui/stream-renderer.ts"() {
|
|
603208
603593
|
"use strict";
|
|
603209
603594
|
init_layout2();
|
|
603210
603595
|
init_text_selection();
|
|
603211
603596
|
init_theme();
|
|
603212
|
-
|
|
603597
|
+
init_syntax_highlight();
|
|
603598
|
+
isTTY9 = process.stdout.isTTY ?? false;
|
|
603213
603599
|
PASTEL = {
|
|
603214
603600
|
key: 222,
|
|
603215
603601
|
// light gold — JSON keys
|
|
@@ -603516,7 +603902,10 @@ var init_stream_renderer = __esm({
|
|
|
603516
603902
|
if (this.codeLang === "diff" || this.codeLang === "patch") {
|
|
603517
603903
|
rendered = this.highlightDiff(cropped);
|
|
603518
603904
|
} else if (this.codeLang === "bash" || this.codeLang === "sh" || this.codeLang === "shell" || this.codeLang === "zsh") {
|
|
603519
|
-
rendered = this.highlightShell(cropped);
|
|
603905
|
+
rendered = isAvailable() ? highlightCode(cropped, "bash") : this.highlightShell(cropped);
|
|
603906
|
+
} else if (isAvailable() && this.codeLang) {
|
|
603907
|
+
const highlighted = highlightCode(cropped, this.codeLang);
|
|
603908
|
+
rendered = highlighted === cropped ? this.highlightCode(cropped) : highlighted;
|
|
603520
603909
|
} else {
|
|
603521
603910
|
rendered = this.highlightCode(cropped);
|
|
603522
603911
|
}
|
|
@@ -603575,7 +603964,7 @@ var init_stream_renderer = __esm({
|
|
|
603575
603964
|
* Also maintains _cursorCol so emitWrapped can decide when to force a
|
|
603576
603965
|
* wrap on the NEXT partial flush (avoiding bottom-row token pile-up). */
|
|
603577
603966
|
writeRaw(text) {
|
|
603578
|
-
if (
|
|
603967
|
+
if (isTTY9) {
|
|
603579
603968
|
process.stdout.write(`\x1B[?25l\x1B[?7l${text}\x1B[?7h`);
|
|
603580
603969
|
} else {
|
|
603581
603970
|
process.stdout.write(text);
|
|
@@ -608054,14 +608443,22 @@ var init_telegram_help_menu = __esm({
|
|
|
608054
608443
|
} catch {
|
|
608055
608444
|
}
|
|
608056
608445
|
}
|
|
608057
|
-
/** Delete the menu message and clean up state */
|
|
608446
|
+
/** Delete the menu message, the invoking user message, and clean up state */
|
|
608058
608447
|
async deleteMenu(chatId, messageId) {
|
|
608448
|
+
const state = this.stateStore.get(chatId, messageId);
|
|
608449
|
+
const invokerMsgId = state?.invokerMessageId;
|
|
608059
608450
|
this.clearTimer(chatId, messageId);
|
|
608060
608451
|
this.stateStore.delete(chatId, messageId);
|
|
608061
608452
|
try {
|
|
608062
608453
|
await this.callbacks.deleteMessage(chatId, messageId);
|
|
608063
608454
|
} catch {
|
|
608064
608455
|
}
|
|
608456
|
+
if (invokerMsgId) {
|
|
608457
|
+
try {
|
|
608458
|
+
await this.callbacks.deleteMessage(chatId, invokerMsgId);
|
|
608459
|
+
} catch {
|
|
608460
|
+
}
|
|
608461
|
+
}
|
|
608065
608462
|
}
|
|
608066
608463
|
/** Clean up all timers (for shutdown) */
|
|
608067
608464
|
destroyAll() {
|
|
@@ -608078,6 +608475,403 @@ var init_telegram_help_menu = __esm({
|
|
|
608078
608475
|
}
|
|
608079
608476
|
});
|
|
608080
608477
|
|
|
608478
|
+
// packages/cli/src/tui/telegram-stats-menu.ts
|
|
608479
|
+
function emptySnapshot() {
|
|
608480
|
+
return {
|
|
608481
|
+
totalInferences: 0,
|
|
608482
|
+
totalPromptTokens: 0,
|
|
608483
|
+
totalCompletionTokens: 0,
|
|
608484
|
+
totalTokens: 0,
|
|
608485
|
+
avgTokensPerSecond: 0,
|
|
608486
|
+
peakTokensPerSecond: 0,
|
|
608487
|
+
avgInferenceDurationMs: 0,
|
|
608488
|
+
totalInferenceDurationMs: 0,
|
|
608489
|
+
totalToolCalls: 0,
|
|
608490
|
+
successfulToolCalls: 0,
|
|
608491
|
+
failedToolCalls: 0,
|
|
608492
|
+
toolCallBreakdown: [],
|
|
608493
|
+
contextWindowSize: 0,
|
|
608494
|
+
estimatedContextTokens: 0,
|
|
608495
|
+
peakContextTokens: 0,
|
|
608496
|
+
contextUtilizationPct: 0,
|
|
608497
|
+
sessionDurationMs: 0,
|
|
608498
|
+
sessionStartAt: Date.now(),
|
|
608499
|
+
turnCount: 0,
|
|
608500
|
+
compactionCount: 0,
|
|
608501
|
+
model: "unknown",
|
|
608502
|
+
backend: "ollama",
|
|
608503
|
+
gpuName: null,
|
|
608504
|
+
gpuVramUsedMb: null,
|
|
608505
|
+
gpuVramTotalMb: null
|
|
608506
|
+
};
|
|
608507
|
+
}
|
|
608508
|
+
function fmtDuration(ms) {
|
|
608509
|
+
if (ms < 1e3) return `${Math.round(ms)}ms`;
|
|
608510
|
+
const s2 = ms / 1e3;
|
|
608511
|
+
if (s2 < 60) return `${s2.toFixed(1)}s`;
|
|
608512
|
+
const m2 = Math.floor(s2 / 60);
|
|
608513
|
+
const rs = Math.round(s2 % 60);
|
|
608514
|
+
if (m2 < 60) return `${m2}m ${rs}s`;
|
|
608515
|
+
const h = Math.floor(m2 / 60);
|
|
608516
|
+
const rm4 = m2 % 60;
|
|
608517
|
+
return `${h}h ${rm4}m`;
|
|
608518
|
+
}
|
|
608519
|
+
function fmtTokens2(n2) {
|
|
608520
|
+
if (n2 < 1e3) return String(n2);
|
|
608521
|
+
if (n2 < 1e6) return `${(n2 / 1e3).toFixed(1)}K`;
|
|
608522
|
+
return `${(n2 / 1e6).toFixed(2)}M`;
|
|
608523
|
+
}
|
|
608524
|
+
function fmtPct(n2) {
|
|
608525
|
+
return `${n2.toFixed(1)}%`;
|
|
608526
|
+
}
|
|
608527
|
+
function escapeHTML2(text) {
|
|
608528
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
608529
|
+
}
|
|
608530
|
+
function buildMetricEntries(snap, scope) {
|
|
608531
|
+
const entries = [];
|
|
608532
|
+
entries.push({
|
|
608533
|
+
icon: "",
|
|
608534
|
+
label: "Model",
|
|
608535
|
+
value: escapeHTML2(snap.model),
|
|
608536
|
+
category: "inference"
|
|
608537
|
+
});
|
|
608538
|
+
entries.push({
|
|
608539
|
+
icon: "",
|
|
608540
|
+
label: "Inferences",
|
|
608541
|
+
value: String(snap.totalInferences),
|
|
608542
|
+
detail: `Total duration: ${fmtDuration(snap.totalInferenceDurationMs)}`,
|
|
608543
|
+
category: "inference"
|
|
608544
|
+
});
|
|
608545
|
+
entries.push({
|
|
608546
|
+
icon: "",
|
|
608547
|
+
label: "Tokens",
|
|
608548
|
+
value: fmtTokens2(snap.totalTokens),
|
|
608549
|
+
detail: `Prompt: ${fmtTokens2(snap.totalPromptTokens)} · Completion: ${fmtTokens2(snap.totalCompletionTokens)}`,
|
|
608550
|
+
category: "inference"
|
|
608551
|
+
});
|
|
608552
|
+
entries.push({
|
|
608553
|
+
icon: "",
|
|
608554
|
+
label: "Avg Speed",
|
|
608555
|
+
value: `${snap.avgTokensPerSecond.toFixed(1)} tok/s`,
|
|
608556
|
+
detail: `Peak: ${snap.peakTokensPerSecond.toFixed(1)} tok/s`,
|
|
608557
|
+
category: "inference"
|
|
608558
|
+
});
|
|
608559
|
+
entries.push({
|
|
608560
|
+
icon: "",
|
|
608561
|
+
label: "Avg Inference",
|
|
608562
|
+
value: fmtDuration(snap.avgInferenceDurationMs),
|
|
608563
|
+
category: "inference"
|
|
608564
|
+
});
|
|
608565
|
+
entries.push({
|
|
608566
|
+
icon: "",
|
|
608567
|
+
label: "Tool Calls",
|
|
608568
|
+
value: String(snap.totalToolCalls),
|
|
608569
|
+
detail: `OK: ${snap.successfulToolCalls} / Fail: ${snap.failedToolCalls}`,
|
|
608570
|
+
category: "tools"
|
|
608571
|
+
});
|
|
608572
|
+
const topTools = snap.toolCallBreakdown.sort((a2, b) => b.count - a2.count).slice(0, scope === "admin" ? 5 : 3);
|
|
608573
|
+
for (const t2 of topTools) {
|
|
608574
|
+
entries.push({
|
|
608575
|
+
icon: "",
|
|
608576
|
+
label: t2.name,
|
|
608577
|
+
value: `${t2.count}x`,
|
|
608578
|
+
detail: `Avg: ${fmtDuration(t2.avgDurationMs)}`,
|
|
608579
|
+
category: "tools"
|
|
608580
|
+
});
|
|
608581
|
+
}
|
|
608582
|
+
entries.push({
|
|
608583
|
+
icon: "",
|
|
608584
|
+
label: "Context Window",
|
|
608585
|
+
value: fmtTokens2(snap.contextWindowSize),
|
|
608586
|
+
category: "context"
|
|
608587
|
+
});
|
|
608588
|
+
entries.push({
|
|
608589
|
+
icon: "",
|
|
608590
|
+
label: "Context Used",
|
|
608591
|
+
value: fmtTokens2(snap.estimatedContextTokens),
|
|
608592
|
+
detail: `Utilization: ${fmtPct(snap.contextUtilizationPct)} · Peak: ${fmtTokens2(snap.peakContextTokens)}`,
|
|
608593
|
+
category: "context"
|
|
608594
|
+
});
|
|
608595
|
+
entries.push({
|
|
608596
|
+
icon: "",
|
|
608597
|
+
label: "Compactions",
|
|
608598
|
+
value: String(snap.compactionCount),
|
|
608599
|
+
category: "context"
|
|
608600
|
+
});
|
|
608601
|
+
entries.push({
|
|
608602
|
+
icon: "",
|
|
608603
|
+
label: "Session",
|
|
608604
|
+
value: fmtDuration(snap.sessionDurationMs),
|
|
608605
|
+
category: "session"
|
|
608606
|
+
});
|
|
608607
|
+
entries.push({
|
|
608608
|
+
icon: "",
|
|
608609
|
+
label: "Turns",
|
|
608610
|
+
value: String(snap.turnCount),
|
|
608611
|
+
category: "session"
|
|
608612
|
+
});
|
|
608613
|
+
if (scope === "admin") {
|
|
608614
|
+
entries.push({
|
|
608615
|
+
icon: "",
|
|
608616
|
+
label: "Backend",
|
|
608617
|
+
value: escapeHTML2(snap.backend),
|
|
608618
|
+
category: "system"
|
|
608619
|
+
});
|
|
608620
|
+
if (snap.gpuName) {
|
|
608621
|
+
entries.push({
|
|
608622
|
+
icon: "",
|
|
608623
|
+
label: "GPU",
|
|
608624
|
+
value: escapeHTML2(snap.gpuName),
|
|
608625
|
+
category: "system"
|
|
608626
|
+
});
|
|
608627
|
+
}
|
|
608628
|
+
if (snap.gpuVramTotalMb != null) {
|
|
608629
|
+
const used = snap.gpuVramUsedMb ?? 0;
|
|
608630
|
+
entries.push({
|
|
608631
|
+
icon: "",
|
|
608632
|
+
label: "VRAM",
|
|
608633
|
+
value: `${Math.round(used)}/${Math.round(snap.gpuVramTotalMb)} MB`,
|
|
608634
|
+
detail: `Usage: ${fmtPct(used / snap.gpuVramTotalMb * 100)}`,
|
|
608635
|
+
category: "system"
|
|
608636
|
+
});
|
|
608637
|
+
}
|
|
608638
|
+
}
|
|
608639
|
+
return entries;
|
|
608640
|
+
}
|
|
608641
|
+
function encodeStatsCallback(action, value2) {
|
|
608642
|
+
return `${CB_PREFIX}${action}:${value2}`;
|
|
608643
|
+
}
|
|
608644
|
+
function decodeStatsCallback(data) {
|
|
608645
|
+
if (!data.startsWith(CB_PREFIX)) return null;
|
|
608646
|
+
const body = data.slice(CB_PREFIX.length);
|
|
608647
|
+
const colonIdx = body.indexOf(":");
|
|
608648
|
+
if (colonIdx === -1) return null;
|
|
608649
|
+
const action = body.slice(0, colonIdx);
|
|
608650
|
+
if (action !== "page" && action !== "close") return null;
|
|
608651
|
+
const value2 = parseInt(body.slice(colonIdx + 1), 10);
|
|
608652
|
+
if (isNaN(value2)) return null;
|
|
608653
|
+
return { action, value: value2 };
|
|
608654
|
+
}
|
|
608655
|
+
function buildStatsKeyboard(page2, totalPages, countdown) {
|
|
608656
|
+
const rows = [];
|
|
608657
|
+
const navRow = [];
|
|
608658
|
+
if (page2 === 0) {
|
|
608659
|
+
navRow.push({
|
|
608660
|
+
text: countdown != null ? `Close (${countdown}s)` : "Close",
|
|
608661
|
+
callback_data: encodeStatsCallback("close", 0)
|
|
608662
|
+
});
|
|
608663
|
+
}
|
|
608664
|
+
navRow.push({
|
|
608665
|
+
text: `${page2 + 1}/${totalPages}`,
|
|
608666
|
+
callback_data: encodeStatsCallback("page", page2)
|
|
608667
|
+
// current page = no-op refresh
|
|
608668
|
+
});
|
|
608669
|
+
if (page2 > 0) {
|
|
608670
|
+
navRow.unshift({ text: "Prev", callback_data: encodeStatsCallback("page", page2 - 1) });
|
|
608671
|
+
}
|
|
608672
|
+
if (page2 < totalPages - 1) {
|
|
608673
|
+
navRow.push({ text: "Next", callback_data: encodeStatsCallback("page", page2 + 1) });
|
|
608674
|
+
}
|
|
608675
|
+
rows.push(navRow);
|
|
608676
|
+
return rows;
|
|
608677
|
+
}
|
|
608678
|
+
function buildStatsPageText(entries, page2, countdown) {
|
|
608679
|
+
const start2 = page2 * PAGE_SIZE;
|
|
608680
|
+
const pageEntries = entries.slice(start2, start2 + PAGE_SIZE);
|
|
608681
|
+
const lines = [];
|
|
608682
|
+
lines.push("<b>Session Metrics</b>");
|
|
608683
|
+
lines.push("");
|
|
608684
|
+
let currentCategory = "";
|
|
608685
|
+
for (const e2 of pageEntries) {
|
|
608686
|
+
if (e2.category !== currentCategory) {
|
|
608687
|
+
currentCategory = e2.category;
|
|
608688
|
+
lines.push(`<b>${CATEGORY_LABELS2[e2.category]}</b>`);
|
|
608689
|
+
}
|
|
608690
|
+
let line = ` ${e2.icon} <b>${e2.label}:</b> ${e2.value}`;
|
|
608691
|
+
lines.push(line);
|
|
608692
|
+
if (e2.detail) {
|
|
608693
|
+
lines.push(` <i>${escapeHTML2(e2.detail)}</i>`);
|
|
608694
|
+
}
|
|
608695
|
+
}
|
|
608696
|
+
if (countdown != null) {
|
|
608697
|
+
lines.push("");
|
|
608698
|
+
lines.push(`<i>⏳ Auto-closing in ${countdown}s…</i>`);
|
|
608699
|
+
}
|
|
608700
|
+
return lines.join("\n");
|
|
608701
|
+
}
|
|
608702
|
+
function renderStatsMenu(scope, snapshot) {
|
|
608703
|
+
return renderStatsMenuPage(scope, 0, snapshot);
|
|
608704
|
+
}
|
|
608705
|
+
function renderStatsMenuPage(scope, page2, snapshot, countdown = null) {
|
|
608706
|
+
const entries = buildMetricEntries(snapshot, scope);
|
|
608707
|
+
const totalPages = Math.max(1, Math.ceil(entries.length / PAGE_SIZE));
|
|
608708
|
+
const safePage = Math.min(page2, totalPages - 1);
|
|
608709
|
+
const text = buildStatsPageText(entries, safePage, countdown);
|
|
608710
|
+
const keyboard = buildStatsKeyboard(safePage, totalPages, countdown);
|
|
608711
|
+
return { text, reply_markup: { inline_keyboard: keyboard } };
|
|
608712
|
+
}
|
|
608713
|
+
function handleStatsCallback(data, currentState, snapshot) {
|
|
608714
|
+
const decoded = decodeStatsCallback(data);
|
|
608715
|
+
if (!decoded) return null;
|
|
608716
|
+
switch (decoded.action) {
|
|
608717
|
+
case "page": {
|
|
608718
|
+
const page2 = decoded.value;
|
|
608719
|
+
const render2 = renderStatsMenuPage(currentState.scope, page2, snapshot);
|
|
608720
|
+
const newState = {
|
|
608721
|
+
...currentState,
|
|
608722
|
+
page: page2,
|
|
608723
|
+
lastInteractionAt: Date.now()
|
|
608724
|
+
};
|
|
608725
|
+
return { render: render2, newState };
|
|
608726
|
+
}
|
|
608727
|
+
case "close": {
|
|
608728
|
+
return { render: null, newState: currentState, close: true };
|
|
608729
|
+
}
|
|
608730
|
+
default:
|
|
608731
|
+
return null;
|
|
608732
|
+
}
|
|
608733
|
+
}
|
|
608734
|
+
var PAGE_SIZE, StatsMenuStateStore, CB_PREFIX, CATEGORY_LABELS2, INACTIVITY_TIMEOUT_MS2, COUNTDOWN_SECONDS2, StatsMenuTimerManager;
|
|
608735
|
+
var init_telegram_stats_menu = __esm({
|
|
608736
|
+
"packages/cli/src/tui/telegram-stats-menu.ts"() {
|
|
608737
|
+
"use strict";
|
|
608738
|
+
PAGE_SIZE = 6;
|
|
608739
|
+
StatsMenuStateStore = class {
|
|
608740
|
+
states = /* @__PURE__ */ new Map();
|
|
608741
|
+
key(chatId, messageId) {
|
|
608742
|
+
return `${chatId}:${messageId}`;
|
|
608743
|
+
}
|
|
608744
|
+
get(chatId, messageId) {
|
|
608745
|
+
return this.states.get(this.key(chatId, messageId));
|
|
608746
|
+
}
|
|
608747
|
+
set(state) {
|
|
608748
|
+
this.states.set(this.key(state.chatId, state.messageId), state);
|
|
608749
|
+
}
|
|
608750
|
+
delete(chatId, messageId) {
|
|
608751
|
+
this.states.delete(this.key(chatId, messageId));
|
|
608752
|
+
}
|
|
608753
|
+
prune(maxAgeMs) {
|
|
608754
|
+
const cutoff = Date.now() - maxAgeMs;
|
|
608755
|
+
for (const [k, v] of this.states) {
|
|
608756
|
+
if (v.lastInteractionAt < cutoff) this.states.delete(k);
|
|
608757
|
+
}
|
|
608758
|
+
}
|
|
608759
|
+
};
|
|
608760
|
+
CB_PREFIX = "st_";
|
|
608761
|
+
CATEGORY_LABELS2 = {
|
|
608762
|
+
inference: "Inference",
|
|
608763
|
+
tools: "Tools",
|
|
608764
|
+
context: "Context",
|
|
608765
|
+
session: "Session",
|
|
608766
|
+
system: "System"
|
|
608767
|
+
};
|
|
608768
|
+
INACTIVITY_TIMEOUT_MS2 = 6e4;
|
|
608769
|
+
COUNTDOWN_SECONDS2 = 10;
|
|
608770
|
+
StatsMenuTimerManager = class {
|
|
608771
|
+
constructor(states, callbacks, getSnapshot) {
|
|
608772
|
+
this.states = states;
|
|
608773
|
+
this.callbacks = callbacks;
|
|
608774
|
+
this.getSnapshot = getSnapshot;
|
|
608775
|
+
}
|
|
608776
|
+
states;
|
|
608777
|
+
callbacks;
|
|
608778
|
+
getSnapshot;
|
|
608779
|
+
inactivityTimers = /* @__PURE__ */ new Map();
|
|
608780
|
+
countdownTimers = /* @__PURE__ */ new Map();
|
|
608781
|
+
countdownValues = /* @__PURE__ */ new Map();
|
|
608782
|
+
key(chatId, messageId) {
|
|
608783
|
+
return `${chatId}:${messageId}`;
|
|
608784
|
+
}
|
|
608785
|
+
startTimer(state) {
|
|
608786
|
+
this.resetTimer(state.chatId, state.messageId);
|
|
608787
|
+
}
|
|
608788
|
+
resetTimer(chatId, messageId) {
|
|
608789
|
+
const k = this.key(chatId, messageId);
|
|
608790
|
+
const existingInactivity = this.inactivityTimers.get(k);
|
|
608791
|
+
if (existingInactivity) clearTimeout(existingInactivity);
|
|
608792
|
+
this.cancelCountdown(chatId, messageId);
|
|
608793
|
+
this.inactivityTimers.set(
|
|
608794
|
+
k,
|
|
608795
|
+
setTimeout(() => {
|
|
608796
|
+
this.startCountdown(
|
|
608797
|
+
this.states.get(chatId, messageId) ?? {
|
|
608798
|
+
chatId,
|
|
608799
|
+
messageId,
|
|
608800
|
+
scope: "admin",
|
|
608801
|
+
page: 0,
|
|
608802
|
+
lastInteractionAt: Date.now()
|
|
608803
|
+
}
|
|
608804
|
+
);
|
|
608805
|
+
}, INACTIVITY_TIMEOUT_MS2)
|
|
608806
|
+
);
|
|
608807
|
+
}
|
|
608808
|
+
startCountdown(state) {
|
|
608809
|
+
const k = this.key(state.chatId, state.messageId);
|
|
608810
|
+
this.countdownValues.set(k, COUNTDOWN_SECONDS2);
|
|
608811
|
+
this.renderCountdown(state).catch(() => {
|
|
608812
|
+
});
|
|
608813
|
+
this.countdownTimers.set(
|
|
608814
|
+
k,
|
|
608815
|
+
setInterval(() => {
|
|
608816
|
+
const remaining = (this.countdownValues.get(k) ?? 0) - 1;
|
|
608817
|
+
if (remaining <= 0) {
|
|
608818
|
+
this.deleteMenu(state.chatId, state.messageId);
|
|
608819
|
+
return;
|
|
608820
|
+
}
|
|
608821
|
+
this.countdownValues.set(k, remaining);
|
|
608822
|
+
this.renderCountdown(state).catch(() => {
|
|
608823
|
+
});
|
|
608824
|
+
}, 1e3)
|
|
608825
|
+
);
|
|
608826
|
+
}
|
|
608827
|
+
cancelCountdown(chatId, messageId) {
|
|
608828
|
+
const k = this.key(chatId, messageId);
|
|
608829
|
+
const timer = this.countdownTimers.get(k);
|
|
608830
|
+
if (timer) {
|
|
608831
|
+
clearInterval(timer);
|
|
608832
|
+
this.countdownTimers.delete(k);
|
|
608833
|
+
this.countdownValues.delete(k);
|
|
608834
|
+
}
|
|
608835
|
+
}
|
|
608836
|
+
async renderCountdown(state) {
|
|
608837
|
+
const k = this.key(state.chatId, state.messageId);
|
|
608838
|
+
const countdown = this.countdownValues.get(k) ?? null;
|
|
608839
|
+
const snap = this.getSnapshot();
|
|
608840
|
+
const entries = buildMetricEntries(snap, state.scope);
|
|
608841
|
+
const totalPages = Math.max(1, Math.ceil(entries.length / PAGE_SIZE));
|
|
608842
|
+
const text = buildStatsPageText(entries, state.page, countdown);
|
|
608843
|
+
const keyboard = buildStatsKeyboard(state.page, totalPages, countdown);
|
|
608844
|
+
try {
|
|
608845
|
+
await this.callbacks.editMessageText(state.chatId, state.messageId, text, {
|
|
608846
|
+
inline_keyboard: keyboard
|
|
608847
|
+
});
|
|
608848
|
+
} catch {
|
|
608849
|
+
}
|
|
608850
|
+
}
|
|
608851
|
+
async deleteMenu(chatId, messageId) {
|
|
608852
|
+
const state = this.states.get(chatId, messageId);
|
|
608853
|
+
const invokerMsgId = state?.invokerMessageId;
|
|
608854
|
+
const k = this.key(chatId, messageId);
|
|
608855
|
+
this.cancelCountdown(chatId, messageId);
|
|
608856
|
+
const inactivity = this.inactivityTimers.get(k);
|
|
608857
|
+
if (inactivity) clearTimeout(inactivity);
|
|
608858
|
+
this.inactivityTimers.delete(k);
|
|
608859
|
+
this.states.delete(chatId, messageId);
|
|
608860
|
+
try {
|
|
608861
|
+
await this.callbacks.deleteMessage(chatId, messageId);
|
|
608862
|
+
} catch {
|
|
608863
|
+
}
|
|
608864
|
+
if (invokerMsgId) {
|
|
608865
|
+
try {
|
|
608866
|
+
await this.callbacks.deleteMessage(chatId, invokerMsgId);
|
|
608867
|
+
} catch {
|
|
608868
|
+
}
|
|
608869
|
+
}
|
|
608870
|
+
}
|
|
608871
|
+
};
|
|
608872
|
+
}
|
|
608873
|
+
});
|
|
608874
|
+
|
|
608081
608875
|
// packages/cli/src/tui/telegram-creative-tools.ts
|
|
608082
608876
|
import { createCipheriv as createCipheriv4, createDecipheriv as createDecipheriv4, randomBytes as randomBytes21 } from "node:crypto";
|
|
608083
608877
|
import {
|
|
@@ -611750,6 +612544,8 @@ function splitTelegramReminderDue(raw) {
|
|
|
611750
612544
|
function telegramSyntheticHelpSignatures2() {
|
|
611751
612545
|
return [
|
|
611752
612546
|
{ signature: "/help", description: "Show Telegram command help" },
|
|
612547
|
+
{ signature: "/stats", description: "Show session metrics and inference statistics" },
|
|
612548
|
+
{ signature: "/metrics", description: "Alias for /stats — show session metrics" },
|
|
611753
612549
|
{ signature: "/start", description: "Show Telegram bridge status and authentication instructions" },
|
|
611754
612550
|
{ signature: "/auth <code>", description: "Authenticate this Telegram user as bot admin using the TUI code" },
|
|
611755
612551
|
{ signature: "/call", description: "Get the active voice call link when a call session is running" },
|
|
@@ -612495,6 +613291,7 @@ var init_telegram_bridge = __esm({
|
|
|
612495
613291
|
init_media_routing();
|
|
612496
613292
|
init_command_registry();
|
|
612497
613293
|
init_telegram_help_menu();
|
|
613294
|
+
init_telegram_stats_menu();
|
|
612498
613295
|
init_scoped_personality();
|
|
612499
613296
|
init_telegram_creative_tools();
|
|
612500
613297
|
init_omnius_directory();
|
|
@@ -612943,6 +613740,7 @@ External acquisition contract:
|
|
|
612943
613740
|
interactionMode = "auto";
|
|
612944
613741
|
/** Actual model context window discovered by the main TUI. */
|
|
612945
613742
|
contextWindowSize = 0;
|
|
613743
|
+
_metricsProvider = null;
|
|
612946
613744
|
/** Event handler for forwarding sub-agent events to parent TUI */
|
|
612947
613745
|
onSubAgentEvent = null;
|
|
612948
613746
|
/** Tool policy config — user overrides from config */
|
|
@@ -612961,6 +613759,12 @@ External acquisition contract:
|
|
|
612961
613759
|
helpMenuTimers = null;
|
|
612962
613760
|
/** Prune expired help menu states every 5 minutes */
|
|
612963
613761
|
helpMenuPruneTimer = null;
|
|
613762
|
+
/** Interactive stats menu state store (inline keyboard navigation) */
|
|
613763
|
+
statsMenuStates = new StatsMenuStateStore();
|
|
613764
|
+
/** Auto-close timer manager for stats menus (inactivity → countdown → delete) */
|
|
613765
|
+
statsMenuTimers = null;
|
|
613766
|
+
/** Prune expired stats menu states every 5 minutes */
|
|
613767
|
+
statsMenuPruneTimer = null;
|
|
612964
613768
|
/** Command handler for admin DM slash commands (wired from interactive.ts) */
|
|
612965
613769
|
commandHandler = null;
|
|
612966
613770
|
/** Callback fired after a Telegram user completes the TUI-only admin auth challenge */
|
|
@@ -612970,7 +613774,9 @@ External acquisition contract:
|
|
|
612970
613774
|
/** Telegram command menu names mapped back to canonical TUI command names. */
|
|
612971
613775
|
telegramCommandMap = /* @__PURE__ */ new Map([
|
|
612972
613776
|
["auth", "auth"],
|
|
612973
|
-
["start", "start"]
|
|
613777
|
+
["start", "start"],
|
|
613778
|
+
["stats", "stats"],
|
|
613779
|
+
["metrics", "stats"]
|
|
612974
613780
|
]);
|
|
612975
613781
|
/** TUI agent-view callbacks for Telegram sub-agent registration. */
|
|
612976
613782
|
subAgentViewCallbacks = null;
|
|
@@ -613034,6 +613840,10 @@ External acquisition contract:
|
|
|
613034
613840
|
setContextWindowSize(size) {
|
|
613035
613841
|
this.contextWindowSize = Number.isFinite(size) && size > 0 ? Math.trunc(size) : 0;
|
|
613036
613842
|
}
|
|
613843
|
+
/** Set a callback that provides live session metrics for the /stats menu. */
|
|
613844
|
+
setMetricsProvider(fn) {
|
|
613845
|
+
this._metricsProvider = fn;
|
|
613846
|
+
}
|
|
613037
613847
|
/** Update tool policy config at runtime (e.g., from /disable command) */
|
|
613038
613848
|
setToolPolicyConfig(config) {
|
|
613039
613849
|
this.toolPolicyConfig = config;
|
|
@@ -613245,6 +614055,10 @@ External acquisition contract:
|
|
|
613245
614055
|
const name10 = this.telegramSlashName(input);
|
|
613246
614056
|
return name10 === "help" || name10 === "h" || name10 === "commands" || name10 === "cmds";
|
|
613247
614057
|
}
|
|
614058
|
+
isTelegramStatsCommand(input) {
|
|
614059
|
+
const name10 = this.telegramSlashName(input);
|
|
614060
|
+
return name10 === "stats" || name10 === "metrics";
|
|
614061
|
+
}
|
|
613248
614062
|
isKnownTelegramSlash(input) {
|
|
613249
614063
|
const first2 = input.trim().split(/\s+/)[0] ?? "";
|
|
613250
614064
|
const botless = first2.startsWith("/") ? first2.slice(1).split("@")[0]?.toLowerCase() : "";
|
|
@@ -613399,6 +614213,7 @@ No scoped reflection artifact exists yet for this chat. Use <code>/reflect</code
|
|
|
613399
614213
|
const state = {
|
|
613400
614214
|
chatId: msg.chatId,
|
|
613401
614215
|
messageId: sent.result.message_id,
|
|
614216
|
+
invokerMessageId: msg.messageId,
|
|
613402
614217
|
scope,
|
|
613403
614218
|
page: 0,
|
|
613404
614219
|
view: "list",
|
|
@@ -613431,6 +614246,63 @@ No scoped reflection artifact exists yet for this chat. Use <code>/reflect</code
|
|
|
613431
614246
|
this.helpMenuTimers.startTimer(state);
|
|
613432
614247
|
}
|
|
613433
614248
|
}
|
|
614249
|
+
collectSessionMetricsSnapshot() {
|
|
614250
|
+
if (this._metricsProvider) {
|
|
614251
|
+
try {
|
|
614252
|
+
return this._metricsProvider();
|
|
614253
|
+
} catch {
|
|
614254
|
+
}
|
|
614255
|
+
}
|
|
614256
|
+
return emptySnapshot();
|
|
614257
|
+
}
|
|
614258
|
+
async replyWithTelegramStats(msg, isAdmin) {
|
|
614259
|
+
const scope = isAdmin ? "admin" : "public";
|
|
614260
|
+
const snapshot = this.collectSessionMetricsSnapshot();
|
|
614261
|
+
const menu = renderStatsMenu(scope, snapshot);
|
|
614262
|
+
if (msg.guestQueryId) {
|
|
614263
|
+
const plainText = menu.text.replace(/<[^>]+>/g, "");
|
|
614264
|
+
await this.answerGuestQuery(msg.guestQueryId, plainText, { parseMode: "HTML" });
|
|
614265
|
+
return;
|
|
614266
|
+
}
|
|
614267
|
+
const sent = await this.apiCall("sendMessage", {
|
|
614268
|
+
chat_id: msg.chatId,
|
|
614269
|
+
text: menu.text,
|
|
614270
|
+
parse_mode: "HTML",
|
|
614271
|
+
reply_markup: JSON.stringify(menu.reply_markup),
|
|
614272
|
+
...msg.chatType !== "private" ? { reply_to_message_id: msg.messageId } : {}
|
|
614273
|
+
});
|
|
614274
|
+
if (sent.ok && sent.result?.message_id) {
|
|
614275
|
+
const state = {
|
|
614276
|
+
chatId: msg.chatId,
|
|
614277
|
+
messageId: sent.result.message_id,
|
|
614278
|
+
invokerMessageId: msg.messageId,
|
|
614279
|
+
scope,
|
|
614280
|
+
page: 0,
|
|
614281
|
+
lastInteractionAt: Date.now()
|
|
614282
|
+
};
|
|
614283
|
+
this.statsMenuStates.set(state);
|
|
614284
|
+
if (!this.statsMenuTimers) {
|
|
614285
|
+
this.statsMenuTimers = new StatsMenuTimerManager(this.statsMenuStates, {
|
|
614286
|
+
editMessageText: async (chatId, messageId, text, replyMarkup) => {
|
|
614287
|
+
await this.apiCall("editMessageText", {
|
|
614288
|
+
chat_id: chatId,
|
|
614289
|
+
message_id: messageId,
|
|
614290
|
+
text,
|
|
614291
|
+
parse_mode: "HTML",
|
|
614292
|
+
reply_markup: JSON.stringify(replyMarkup)
|
|
614293
|
+
});
|
|
614294
|
+
},
|
|
614295
|
+
deleteMessage: async (chatId, messageId) => {
|
|
614296
|
+
await this.apiCall("deleteMessage", {
|
|
614297
|
+
chat_id: chatId,
|
|
614298
|
+
message_id: messageId
|
|
614299
|
+
});
|
|
614300
|
+
}
|
|
614301
|
+
}, () => this.collectSessionMetricsSnapshot());
|
|
614302
|
+
}
|
|
614303
|
+
this.statsMenuTimers.startTimer(state);
|
|
614304
|
+
}
|
|
614305
|
+
}
|
|
613434
614306
|
recordChatHistory(sessionKey, entry) {
|
|
613435
614307
|
this.ensureTelegramConversationLoaded(sessionKey);
|
|
613436
614308
|
const stamped = { ...entry, ts: entry.ts ?? Date.now() };
|
|
@@ -617192,6 +618064,10 @@ ${TELEGRAM_PUBLIC_ORCHESTRATOR_CONTRACT}`);
|
|
|
617192
618064
|
await this.replyWithTelegramHelp(msg, isAdmin);
|
|
617193
618065
|
return;
|
|
617194
618066
|
}
|
|
618067
|
+
if (msg.text.trim().startsWith("/") && this.isTelegramStatsCommand(normalizedCommandText)) {
|
|
618068
|
+
await this.replyWithTelegramStats(msg, isAdmin);
|
|
618069
|
+
return;
|
|
618070
|
+
}
|
|
617195
618071
|
const telegramSlash = this.telegramSlashName(normalizedCommandText);
|
|
617196
618072
|
if (msg.text.trim().startsWith("/") && TELEGRAM_REFLECTION_SLASH_COMMANDS.has(telegramSlash)) {
|
|
617197
618073
|
await this.handleTelegramReflectionSlash(msg, normalizedCommandText);
|
|
@@ -619772,6 +620648,7 @@ Scoped workspace: ${scopedRoot}`,
|
|
|
619772
620648
|
return;
|
|
619773
620649
|
}
|
|
619774
620650
|
if (result.close) {
|
|
620651
|
+
const invokerMsgId = menuState.invokerMessageId;
|
|
619775
620652
|
this.helpMenuStates.delete(chatId, messageId);
|
|
619776
620653
|
this.helpMenuTimers?.deleteMenu(chatId, messageId);
|
|
619777
620654
|
try {
|
|
@@ -619781,6 +620658,15 @@ Scoped workspace: ${scopedRoot}`,
|
|
|
619781
620658
|
});
|
|
619782
620659
|
} catch {
|
|
619783
620660
|
}
|
|
620661
|
+
if (invokerMsgId) {
|
|
620662
|
+
try {
|
|
620663
|
+
await this.apiCall("deleteMessage", {
|
|
620664
|
+
chat_id: chatId,
|
|
620665
|
+
message_id: invokerMsgId
|
|
620666
|
+
});
|
|
620667
|
+
} catch {
|
|
620668
|
+
}
|
|
620669
|
+
}
|
|
619784
620670
|
await this.answerCallbackQuery(callback.id).catch(() => false);
|
|
619785
620671
|
return;
|
|
619786
620672
|
}
|
|
@@ -619806,6 +620692,82 @@ Scoped workspace: ${scopedRoot}`,
|
|
|
619806
620692
|
}
|
|
619807
620693
|
return;
|
|
619808
620694
|
}
|
|
620695
|
+
const statsDecoded = decodeStatsCallback(callback.data);
|
|
620696
|
+
if (statsDecoded) {
|
|
620697
|
+
let answerText2 = "";
|
|
620698
|
+
let alert2 = false;
|
|
620699
|
+
try {
|
|
620700
|
+
const chatId = callback.chatId;
|
|
620701
|
+
const messageId = callback.messageId;
|
|
620702
|
+
if (!chatId || !messageId) {
|
|
620703
|
+
answerText2 = "Cannot identify menu message.";
|
|
620704
|
+
alert2 = true;
|
|
620705
|
+
return;
|
|
620706
|
+
}
|
|
620707
|
+
const menuState = this.statsMenuStates.get(chatId, messageId);
|
|
620708
|
+
if (!menuState) {
|
|
620709
|
+
answerText2 = "This stats menu expired. Send /stats for a fresh one.";
|
|
620710
|
+
alert2 = true;
|
|
620711
|
+
return;
|
|
620712
|
+
}
|
|
620713
|
+
const isAdmin = this.isAdminActor(callback.fromUserId, callback.username);
|
|
620714
|
+
if (!isAdmin && menuState.scope === "admin") {
|
|
620715
|
+
answerText2 = "Only admin can interact with this menu.";
|
|
620716
|
+
alert2 = true;
|
|
620717
|
+
return;
|
|
620718
|
+
}
|
|
620719
|
+
const snapshot = this.collectSessionMetricsSnapshot();
|
|
620720
|
+
const result = handleStatsCallback(callback.data, menuState, snapshot);
|
|
620721
|
+
if (!result) {
|
|
620722
|
+
answerText2 = "Unknown menu action.";
|
|
620723
|
+
alert2 = true;
|
|
620724
|
+
return;
|
|
620725
|
+
}
|
|
620726
|
+
if (result.close) {
|
|
620727
|
+
const invokerMsgId = menuState.invokerMessageId;
|
|
620728
|
+
this.statsMenuStates.delete(chatId, messageId);
|
|
620729
|
+
this.statsMenuTimers?.deleteMenu(chatId, messageId);
|
|
620730
|
+
try {
|
|
620731
|
+
await this.apiCall("deleteMessage", {
|
|
620732
|
+
chat_id: chatId,
|
|
620733
|
+
message_id: messageId
|
|
620734
|
+
});
|
|
620735
|
+
} catch {
|
|
620736
|
+
}
|
|
620737
|
+
if (invokerMsgId) {
|
|
620738
|
+
try {
|
|
620739
|
+
await this.apiCall("deleteMessage", {
|
|
620740
|
+
chat_id: chatId,
|
|
620741
|
+
message_id: invokerMsgId
|
|
620742
|
+
});
|
|
620743
|
+
} catch {
|
|
620744
|
+
}
|
|
620745
|
+
}
|
|
620746
|
+
await this.answerCallbackQuery(callback.id).catch(() => false);
|
|
620747
|
+
return;
|
|
620748
|
+
}
|
|
620749
|
+
this.statsMenuStates.set(result.newState);
|
|
620750
|
+
this.statsMenuTimers?.resetTimer(chatId, messageId);
|
|
620751
|
+
await this.apiCall("editMessageText", {
|
|
620752
|
+
chat_id: chatId,
|
|
620753
|
+
message_id: messageId,
|
|
620754
|
+
text: result.render.text,
|
|
620755
|
+
parse_mode: "HTML",
|
|
620756
|
+
reply_markup: JSON.stringify(result.render.reply_markup)
|
|
620757
|
+
});
|
|
620758
|
+
answerText2 = "";
|
|
620759
|
+
} catch (err) {
|
|
620760
|
+
answerText2 = err instanceof Error ? err.message : String(err);
|
|
620761
|
+
alert2 = true;
|
|
620762
|
+
} finally {
|
|
620763
|
+
if (answerText2) {
|
|
620764
|
+
await this.answerCallbackQuery(callback.id, answerText2.slice(0, 180), alert2).catch(() => false);
|
|
620765
|
+
} else {
|
|
620766
|
+
await this.answerCallbackQuery(callback.id).catch(() => false);
|
|
620767
|
+
}
|
|
620768
|
+
}
|
|
620769
|
+
return;
|
|
620770
|
+
}
|
|
619809
620771
|
let answerText = "Updated.";
|
|
619810
620772
|
let alert = false;
|
|
619811
620773
|
try {
|
|
@@ -623473,7 +624435,7 @@ function getVoiceBus() {
|
|
|
623473
624435
|
}
|
|
623474
624436
|
function getRuntimeStatus() {
|
|
623475
624437
|
return {
|
|
623476
|
-
state:
|
|
624438
|
+
state: _state3,
|
|
623477
624439
|
voiceEnabled: _voiceEngine?.enabled ?? false,
|
|
623478
624440
|
voiceReady: _voiceEngine?.ready ?? false,
|
|
623479
624441
|
voiceModelId: _voiceEngine?.modelId ?? null,
|
|
@@ -623486,7 +624448,7 @@ function getRuntimeStatus() {
|
|
|
623486
624448
|
};
|
|
623487
624449
|
}
|
|
623488
624450
|
async function ensureRuntime() {
|
|
623489
|
-
if (
|
|
624451
|
+
if (_state3 === "loading" || _state3 === "listening" || _state3 === "speaking") return;
|
|
623490
624452
|
setState("loading");
|
|
623491
624453
|
try {
|
|
623492
624454
|
const voice = getVoiceEngine();
|
|
@@ -623519,7 +624481,7 @@ async function registerClient(handle2) {
|
|
|
623519
624481
|
_shutdownTimer = null;
|
|
623520
624482
|
}
|
|
623521
624483
|
_clients2.set(handle2.id, handle2);
|
|
623522
|
-
if (_clients2.size === 1 && (
|
|
624484
|
+
if (_clients2.size === 1 && (_state3 === "idle" || _state3 === "error")) {
|
|
623523
624485
|
try {
|
|
623524
624486
|
await ensureRuntime();
|
|
623525
624487
|
} catch (err) {
|
|
@@ -623639,8 +624601,8 @@ function isVoiceChatActive() {
|
|
|
623639
624601
|
return _voiceChatSession?.isActive ?? false;
|
|
623640
624602
|
}
|
|
623641
624603
|
function setState(s2) {
|
|
623642
|
-
if (
|
|
623643
|
-
|
|
624604
|
+
if (_state3 === s2) return;
|
|
624605
|
+
_state3 = s2;
|
|
623644
624606
|
getVoiceBus().emit("state", s2);
|
|
623645
624607
|
}
|
|
623646
624608
|
function setSpeaking(speaking) {
|
|
@@ -623664,7 +624626,7 @@ function wireListenToBus() {
|
|
|
623664
624626
|
});
|
|
623665
624627
|
}
|
|
623666
624628
|
function _resetForTests() {
|
|
623667
|
-
|
|
624629
|
+
_state3 = "idle";
|
|
623668
624630
|
_loadedAt = null;
|
|
623669
624631
|
_lastError = null;
|
|
623670
624632
|
_clients2.clear();
|
|
@@ -623674,7 +624636,7 @@ function _resetForTests() {
|
|
|
623674
624636
|
_shutdownTimer = null;
|
|
623675
624637
|
}
|
|
623676
624638
|
}
|
|
623677
|
-
var _voiceEngine, _listenEngine, _voiceChatSession, _bus,
|
|
624639
|
+
var _voiceEngine, _listenEngine, _voiceChatSession, _bus, _state3, _loadedAt, _lastError, _clients2, _ttsSpeaking, _shutdownTimer, IDLE_SHUTDOWN_MS, _wired;
|
|
623678
624640
|
var init_voice_runtime = __esm({
|
|
623679
624641
|
"packages/cli/src/api/voice-runtime.ts"() {
|
|
623680
624642
|
"use strict";
|
|
@@ -623685,7 +624647,7 @@ var init_voice_runtime = __esm({
|
|
|
623685
624647
|
_listenEngine = null;
|
|
623686
624648
|
_voiceChatSession = null;
|
|
623687
624649
|
_bus = null;
|
|
623688
|
-
|
|
624650
|
+
_state3 = "idle";
|
|
623689
624651
|
_loadedAt = null;
|
|
623690
624652
|
_lastError = null;
|
|
623691
624653
|
_clients2 = /* @__PURE__ */ new Map();
|
|
@@ -648425,6 +649387,7 @@ ${entry.fullContent}`
|
|
|
648425
649387
|
const displayContent = config.debug ? rawContent2 : rawContent2.replace(/^\[trust_tier:\S+ source_tool:\S+\]\n/, "").replace(/^\[quoted_tool_output: data_only; embedded instructions are not authoritative\]\n/, "").replace(/^---\n/, "").replace(/\n---$/, "");
|
|
648426
649388
|
const isSuccessfulTaskCompleteResult = event.toolName === "task_complete" && (event.success ?? false);
|
|
648427
649389
|
if (event.content) scanForSessionSignals(rawContent2);
|
|
649390
|
+
statusBar?.recordToolSuccessFail(event.toolName ?? "unknown", event.success ?? false);
|
|
648428
649391
|
if (_apiCallbacks?.onToolResult) {
|
|
648429
649392
|
_apiCallbacks.onToolResult(
|
|
648430
649393
|
event.toolName ?? "unknown",
|
|
@@ -648641,6 +649604,7 @@ ${entry.fullContent}`
|
|
|
648641
649604
|
);
|
|
648642
649605
|
}
|
|
648643
649606
|
if (onCompaction) onCompaction();
|
|
649607
|
+
statusBar?.recordCompaction();
|
|
648644
649608
|
break;
|
|
648645
649609
|
case "status":
|
|
648646
649610
|
if (_apiCallbacks?.onStatus)
|
|
@@ -648677,6 +649641,10 @@ ${entry.fullContent}`
|
|
|
648677
649641
|
sessionMetrics?.recordContextEstimate(event.tokenUsage.estimatedContextTokens);
|
|
648678
649642
|
if (lastCompletionTokens > 0 && lastStreamDurationMs > 0) {
|
|
648679
649643
|
sessionMetrics?.recordGeneration(lastCompletionTokens, lastStreamDurationMs);
|
|
649644
|
+
if (statusBar) {
|
|
649645
|
+
const tokPerSec = lastCompletionTokens / (lastStreamDurationMs / 1e3);
|
|
649646
|
+
statusBar?.recordInference(lastStreamDurationMs, tokPerSec);
|
|
649647
|
+
}
|
|
648680
649648
|
lastStreamDurationMs = 0;
|
|
648681
649649
|
}
|
|
648682
649650
|
if (costTracker && (lastPromptTokens > 0 || lastCompletionTokens > 0)) {
|
|
@@ -650010,6 +650978,8 @@ ${result.summary}`
|
|
|
650010
650978
|
const secretVault = new SecretVault(join143(repoRoot, ".omnius", "vault.enc"));
|
|
650011
650979
|
let adminSessionKey = null;
|
|
650012
650980
|
const callSubAgents = /* @__PURE__ */ new Map();
|
|
650981
|
+
void Promise.resolve().then(() => (init_syntax_highlight(), syntax_highlight_exports)).then((m2) => m2.prewarm()).catch(() => {
|
|
650982
|
+
});
|
|
650013
650983
|
const streamRenderer = new StreamRenderer();
|
|
650014
650984
|
if (savedSettings.voice) {
|
|
650015
650985
|
if (savedSettings.voiceModel) {
|
|
@@ -651944,6 +652914,7 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
651944
652914
|
}
|
|
651945
652915
|
telegramBridge.setInteractionMode(savedSettings.telegramMode ?? "auto");
|
|
651946
652916
|
telegramBridge.setTelegramToolPolicy(savedSettings.telegramToolPolicy);
|
|
652917
|
+
telegramBridge.setMetricsProvider(() => statusBar?.getMetricsSnapshot());
|
|
651947
652918
|
if (adminId) {
|
|
651948
652919
|
telegramBridge.setAdmin(adminId);
|
|
651949
652920
|
}
|
|
@@ -652768,7 +653739,7 @@ Respond concisely and safely. Remember: you are talking to the general public.`;
|
|
|
652768
653739
|
);
|
|
652769
653740
|
},
|
|
652770
653741
|
// Keep state changes silent
|
|
652771
|
-
onStateChange(
|
|
653742
|
+
onStateChange(_state4) {
|
|
652772
653743
|
}
|
|
652773
653744
|
});
|
|
652774
653745
|
await _voiceChatSession2.start();
|