omnius 1.0.76 → 1.0.77
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 +212 -36
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -610245,44 +610245,157 @@ function telegramDecisionNote(parsed, keys, nestedKeys = ["internal_notes", "int
|
|
|
610245
610245
|
}
|
|
610246
610246
|
return void 0;
|
|
610247
610247
|
}
|
|
610248
|
+
function uniqueTelegramJsonCandidates(candidates) {
|
|
610249
|
+
const seen = /* @__PURE__ */ new Set();
|
|
610250
|
+
const unique = [];
|
|
610251
|
+
for (const candidate of candidates) {
|
|
610252
|
+
const clean5 = candidate.trim();
|
|
610253
|
+
if (!clean5 || seen.has(clean5)) continue;
|
|
610254
|
+
seen.add(clean5);
|
|
610255
|
+
unique.push(clean5);
|
|
610256
|
+
}
|
|
610257
|
+
return unique;
|
|
610258
|
+
}
|
|
610259
|
+
function extractBalancedTelegramJsonObjects(text) {
|
|
610260
|
+
const objects = [];
|
|
610261
|
+
let start2 = -1;
|
|
610262
|
+
let depth = 0;
|
|
610263
|
+
let inString = false;
|
|
610264
|
+
let escaped = false;
|
|
610265
|
+
for (let idx = 0; idx < text.length; idx++) {
|
|
610266
|
+
const ch = text[idx];
|
|
610267
|
+
if (inString) {
|
|
610268
|
+
if (escaped) {
|
|
610269
|
+
escaped = false;
|
|
610270
|
+
} else if (ch === "\\") {
|
|
610271
|
+
escaped = true;
|
|
610272
|
+
} else if (ch === '"') {
|
|
610273
|
+
inString = false;
|
|
610274
|
+
}
|
|
610275
|
+
continue;
|
|
610276
|
+
}
|
|
610277
|
+
if (ch === '"') {
|
|
610278
|
+
inString = true;
|
|
610279
|
+
continue;
|
|
610280
|
+
}
|
|
610281
|
+
if (ch === "{") {
|
|
610282
|
+
if (depth === 0) start2 = idx;
|
|
610283
|
+
depth += 1;
|
|
610284
|
+
continue;
|
|
610285
|
+
}
|
|
610286
|
+
if (ch === "}" && depth > 0) {
|
|
610287
|
+
depth -= 1;
|
|
610288
|
+
if (depth === 0 && start2 >= 0) {
|
|
610289
|
+
objects.push(text.slice(start2, idx + 1));
|
|
610290
|
+
start2 = -1;
|
|
610291
|
+
}
|
|
610292
|
+
}
|
|
610293
|
+
}
|
|
610294
|
+
return objects;
|
|
610295
|
+
}
|
|
610296
|
+
function telegramDecisionJsonCandidates(text) {
|
|
610297
|
+
const cleaned = stripTelegramHiddenThinking(text).trim();
|
|
610298
|
+
if (!cleaned) return [];
|
|
610299
|
+
const candidates = [];
|
|
610300
|
+
const fenced = cleaned.matchAll(/```(?:json)?\s*([\s\S]*?)```/gi);
|
|
610301
|
+
for (const match of fenced) {
|
|
610302
|
+
if (match[1]) candidates.push(match[1]);
|
|
610303
|
+
}
|
|
610304
|
+
candidates.push(cleaned);
|
|
610305
|
+
candidates.push(cleaned.replace(/```(?:json)?/gi, "").replace(/```/g, "").trim());
|
|
610306
|
+
candidates.push(cleaned.replace(/^\s*(?:json|decision|router decision)\s*:?\s*/i, "").trim());
|
|
610307
|
+
const expanded = [];
|
|
610308
|
+
for (const candidate of candidates) {
|
|
610309
|
+
if (!candidate.trim()) continue;
|
|
610310
|
+
expanded.push(candidate);
|
|
610311
|
+
expanded.push(...extractBalancedTelegramJsonObjects(candidate));
|
|
610312
|
+
}
|
|
610313
|
+
return uniqueTelegramJsonCandidates(expanded);
|
|
610314
|
+
}
|
|
610315
|
+
function telegramDecisionOutputHasDanglingJson(text) {
|
|
610316
|
+
const cleaned = stripTelegramHiddenThinking(text).trim();
|
|
610317
|
+
if (!cleaned || extractBalancedTelegramJsonObjects(cleaned).length > 0) return false;
|
|
610318
|
+
let depth = 0;
|
|
610319
|
+
let inString = false;
|
|
610320
|
+
let escaped = false;
|
|
610321
|
+
for (let idx = 0; idx < cleaned.length; idx++) {
|
|
610322
|
+
const ch = cleaned[idx];
|
|
610323
|
+
if (inString) {
|
|
610324
|
+
if (escaped) {
|
|
610325
|
+
escaped = false;
|
|
610326
|
+
} else if (ch === "\\") {
|
|
610327
|
+
escaped = true;
|
|
610328
|
+
} else if (ch === '"') {
|
|
610329
|
+
inString = false;
|
|
610330
|
+
}
|
|
610331
|
+
continue;
|
|
610332
|
+
}
|
|
610333
|
+
if (ch === '"') {
|
|
610334
|
+
inString = true;
|
|
610335
|
+
continue;
|
|
610336
|
+
}
|
|
610337
|
+
if (ch === "{") depth += 1;
|
|
610338
|
+
if (ch === "}" && depth > 0) depth -= 1;
|
|
610339
|
+
}
|
|
610340
|
+
return depth > 0;
|
|
610341
|
+
}
|
|
610342
|
+
function telegramRouterRawPreview(text, maxLength = 320) {
|
|
610343
|
+
const clean5 = stripTelegramHiddenThinking(text).replace(/\s+/g, " ").trim();
|
|
610344
|
+
if (!clean5) return void 0;
|
|
610345
|
+
return clean5.length > maxLength ? `${clean5.slice(0, Math.max(0, maxLength - 3)).trimEnd()}...` : clean5;
|
|
610346
|
+
}
|
|
610347
|
+
function telegramDecisionRecoverableFlag(text) {
|
|
610348
|
+
for (const jsonText of telegramDecisionJsonCandidates(text)) {
|
|
610349
|
+
try {
|
|
610350
|
+
const parsed = JSON.parse(jsonText);
|
|
610351
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue;
|
|
610352
|
+
const recoverable = parsed["recoverable"];
|
|
610353
|
+
if (typeof recoverable === "boolean") return recoverable;
|
|
610354
|
+
} catch {
|
|
610355
|
+
continue;
|
|
610356
|
+
}
|
|
610357
|
+
}
|
|
610358
|
+
return void 0;
|
|
610359
|
+
}
|
|
610248
610360
|
function parseTelegramInteractionDecision(text, forcedRoute, options2 = {}) {
|
|
610249
|
-
const
|
|
610250
|
-
|
|
610251
|
-
|
|
610252
|
-
|
|
610253
|
-
|
|
610254
|
-
|
|
610255
|
-
|
|
610256
|
-
|
|
610257
|
-
|
|
610258
|
-
|
|
610259
|
-
|
|
610260
|
-
|
|
610261
|
-
|
|
610262
|
-
|
|
610263
|
-
|
|
610264
|
-
|
|
610265
|
-
|
|
610266
|
-
|
|
610267
|
-
|
|
610268
|
-
|
|
610269
|
-
|
|
610270
|
-
|
|
610271
|
-
|
|
610272
|
-
|
|
610273
|
-
|
|
610274
|
-
|
|
610275
|
-
|
|
610276
|
-
|
|
610277
|
-
|
|
610278
|
-
|
|
610279
|
-
|
|
610280
|
-
|
|
610281
|
-
|
|
610282
|
-
}
|
|
610283
|
-
|
|
610284
|
-
|
|
610361
|
+
for (const jsonText of telegramDecisionJsonCandidates(text)) {
|
|
610362
|
+
try {
|
|
610363
|
+
const parsed = JSON.parse(jsonText);
|
|
610364
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue;
|
|
610365
|
+
const parsedRoute = parsed["route"] === "chat" || parsed["route"] === "action" ? parsed["route"] : null;
|
|
610366
|
+
const route = forcedRoute ?? parsedRoute;
|
|
610367
|
+
if (!route) continue;
|
|
610368
|
+
const shouldReplyRaw = parsed["should_reply"] ?? parsed["shouldReply"];
|
|
610369
|
+
const shouldReply = typeof shouldReplyRaw === "boolean" ? shouldReplyRaw : options2.defaultShouldReply ?? true;
|
|
610370
|
+
const confidenceRaw = Number(parsed["confidence"]);
|
|
610371
|
+
const confidence2 = Number.isFinite(confidenceRaw) ? Math.max(0, Math.min(1, confidenceRaw)) : 0;
|
|
610372
|
+
const reason = String(parsed["reason"] ?? "live inference decision").slice(0, 240);
|
|
610373
|
+
const attentionDeltaRaw = Number(parsed["attention_delta"] ?? parsed["attentionDelta"]);
|
|
610374
|
+
const attentionScoreRaw = Number(parsed["attention_score"] ?? parsed["attentionScore"]);
|
|
610375
|
+
const nextMessagesRaw = Number(parsed["next_check_after_messages"] ?? parsed["nextCheckAfterMessages"]);
|
|
610376
|
+
const nextMsRaw = Number(parsed["next_check_after_ms"] ?? parsed["nextCheckAfterMs"]);
|
|
610377
|
+
return {
|
|
610378
|
+
route,
|
|
610379
|
+
shouldReply,
|
|
610380
|
+
confidence: confidence2,
|
|
610381
|
+
reason,
|
|
610382
|
+
source: forcedRoute ? "forced-mode" : "live-inference",
|
|
610383
|
+
raw: text,
|
|
610384
|
+
attentionState: parseStimulationPhase(parsed["attention_state"] ?? parsed["attentionState"]),
|
|
610385
|
+
attentionDelta: Number.isFinite(attentionDeltaRaw) ? Math.max(-1, Math.min(1, attentionDeltaRaw)) : void 0,
|
|
610386
|
+
attentionScore: Number.isFinite(attentionScoreRaw) ? Math.max(0, Math.min(1, attentionScoreRaw)) : void 0,
|
|
610387
|
+
nextCheckAfterMessages: Number.isFinite(nextMessagesRaw) ? Math.max(1, Math.floor(nextMessagesRaw)) : void 0,
|
|
610388
|
+
nextCheckAfterMs: Number.isFinite(nextMsRaw) ? Math.max(0, Math.floor(nextMsRaw)) : void 0,
|
|
610389
|
+
silentDisposition: telegramDecisionNote(parsed, ["silent_disposition", "silentDisposition", "disposition"]),
|
|
610390
|
+
mentalNote: telegramDecisionNote(parsed, ["mental_note", "mentalNote", "observation", "insight"]),
|
|
610391
|
+
memoryNote: telegramDecisionNote(parsed, ["memory_note", "memoryNote", "memory"]),
|
|
610392
|
+
relationshipNote: telegramDecisionNote(parsed, ["relationship_note", "relationshipNote", "relationship"])
|
|
610393
|
+
};
|
|
610394
|
+
} catch {
|
|
610395
|
+
continue;
|
|
610396
|
+
}
|
|
610285
610397
|
}
|
|
610398
|
+
return null;
|
|
610286
610399
|
}
|
|
610287
610400
|
function parseTelegramTimeRangeQuery(query, now = /* @__PURE__ */ new Date()) {
|
|
610288
610401
|
const original = String(query || "");
|
|
@@ -615233,6 +615346,57 @@ ${lines.join("\n")}`);
|
|
|
615233
615346
|
nextAnalysisAfterMs: decision.nextCheckAfterMs
|
|
615234
615347
|
});
|
|
615235
615348
|
}
|
|
615349
|
+
async repairTelegramInteractionDecision(backend, rawOutput, forcedRoute, timeoutMs) {
|
|
615350
|
+
const rawPreview = telegramRouterRawPreview(rawOutput, 4e3);
|
|
615351
|
+
if (!rawPreview || telegramDecisionOutputHasDanglingJson(rawOutput)) return null;
|
|
615352
|
+
const routeInstruction = forcedRoute ? `The route is operator-forced and must be "${forcedRoute}".` : `Preserve the original route if present; otherwise choose chat or action only if the original output clearly implies one.`;
|
|
615353
|
+
const prompt = [
|
|
615354
|
+
`Repair this Telegram attention-router output into strict JSON.`,
|
|
615355
|
+
`Do not make a new social decision from the Telegram message. Only preserve the decision already present in the router output.`,
|
|
615356
|
+
`If the original output does not contain a recoverable route and should_reply decision, return recoverable=false with should_reply=false and confidence=0.`,
|
|
615357
|
+
routeInstruction,
|
|
615358
|
+
``,
|
|
615359
|
+
`Return JSON only with this schema:`,
|
|
615360
|
+
`{"recoverable":true|false,"route":"chat"|"action","should_reply":true|false,"confidence":0.0-1.0,"reason":"short reason","attention_state":"idle"|"observing"|"engaged"|"cooldown","attention_delta":-1.0..1.0,"next_check_after_messages":1..12,"silent_disposition":"short outcome-level disposition","mental_note":"short outcome-level observation","memory_note":"short memory/summary update","relationship_note":"short relationship/thread note"}`,
|
|
615361
|
+
``,
|
|
615362
|
+
`Original router output:`,
|
|
615363
|
+
rawPreview
|
|
615364
|
+
].join("\n");
|
|
615365
|
+
try {
|
|
615366
|
+
const result = await backend.chatCompletion({
|
|
615367
|
+
messages: [
|
|
615368
|
+
{
|
|
615369
|
+
role: "system",
|
|
615370
|
+
content: "You repair a Telegram router response into strict JSON without changing the underlying decision."
|
|
615371
|
+
},
|
|
615372
|
+
{ role: "user", content: prompt }
|
|
615373
|
+
],
|
|
615374
|
+
tools: [],
|
|
615375
|
+
temperature: 0,
|
|
615376
|
+
maxTokens: 500,
|
|
615377
|
+
timeoutMs: Math.min(Math.max(timeoutMs, 3e3), 8e3),
|
|
615378
|
+
think: false
|
|
615379
|
+
});
|
|
615380
|
+
const repairedText = result.choices[0]?.message?.content ?? "";
|
|
615381
|
+
if (telegramDecisionRecoverableFlag(repairedText) === false) return null;
|
|
615382
|
+
const parsed = parseTelegramInteractionDecision(repairedText, forcedRoute, {
|
|
615383
|
+
defaultShouldReply: false
|
|
615384
|
+
});
|
|
615385
|
+
if (!parsed) return null;
|
|
615386
|
+
return {
|
|
615387
|
+
...parsed,
|
|
615388
|
+
reason: `recovered router decision: ${parsed.reason}`.slice(0, 240),
|
|
615389
|
+
raw: `${rawOutput}
|
|
615390
|
+
|
|
615391
|
+
[repaired router decision]
|
|
615392
|
+
${repairedText}`,
|
|
615393
|
+
mentalNote: parsed.mentalNote ?? "router decision recovered from non-JSON model output",
|
|
615394
|
+
memoryNote: parsed.memoryNote ?? "router repair preserved the model-derived attention decision"
|
|
615395
|
+
};
|
|
615396
|
+
} catch {
|
|
615397
|
+
return null;
|
|
615398
|
+
}
|
|
615399
|
+
}
|
|
615236
615400
|
async inferTelegramInteractionDecision(msg, toolContext) {
|
|
615237
615401
|
const config = this.agentConfig;
|
|
615238
615402
|
const forcedRoute = this.interactionMode === "chat" || this.interactionMode === "action" ? this.interactionMode : null;
|
|
@@ -615338,6 +615502,17 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`
|
|
|
615338
615502
|
this.applyTelegramStimulationDecision(sessionKey, parsed);
|
|
615339
615503
|
return parsed;
|
|
615340
615504
|
}
|
|
615505
|
+
const repaired = await this.repairTelegramInteractionDecision(
|
|
615506
|
+
backend,
|
|
615507
|
+
text,
|
|
615508
|
+
forcedRoute,
|
|
615509
|
+
config.timeoutMs ?? 3e4
|
|
615510
|
+
);
|
|
615511
|
+
if (repaired) {
|
|
615512
|
+
this.applyTelegramStimulationDecision(sessionKey, repaired);
|
|
615513
|
+
return repaired;
|
|
615514
|
+
}
|
|
615515
|
+
const invalidRouterPreview = telegramRouterRawPreview(text);
|
|
615341
615516
|
const fallback2 = {
|
|
615342
615517
|
route: forcedRoute ?? (isGroup ? "action" : "chat"),
|
|
615343
615518
|
shouldReply: false,
|
|
@@ -615346,6 +615521,7 @@ ${this.quoteTelegramContextBlock(msg.text, 1200)}`
|
|
|
615346
615521
|
source: "inference-unavailable",
|
|
615347
615522
|
silentDisposition: "retained as context without replying because the router decision could not be parsed",
|
|
615348
615523
|
mentalNote: "router produced an invalid attention decision payload",
|
|
615524
|
+
memoryNote: invalidRouterPreview ? `invalid router output preview: ${invalidRouterPreview}` : void 0,
|
|
615349
615525
|
raw: text
|
|
615350
615526
|
};
|
|
615351
615527
|
this.applyTelegramStimulationDecision(sessionKey, fallback2);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omnius",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.77",
|
|
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.77",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"image-to-ascii"
|
|
12
12
|
],
|
package/package.json
CHANGED