chainlesschain 0.143.0 → 0.145.0
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/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +157 -27
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +152 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +190 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +414 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +580 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dlp.js +172 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +182 -27
- package/src/commands/fflag.js +74 -22
- package/src/commands/git.js +177 -37
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +179 -27
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/nostr.js +178 -27
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/recommend.js +177 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +157 -32
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/topiccls.js +146 -33
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/webfetch.js +141 -32
- package/src/commands/zkp.js +184 -28
- package/src/index.js +40 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +288 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/bi-engine.js +283 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +296 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dlp-engine.js +287 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/inference-network.js +308 -51
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +281 -47
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/nostr-bridge.js +286 -49
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/matrix-bridge.js
CHANGED
|
@@ -447,25 +447,53 @@ export function _resetState() {
|
|
|
447
447
|
};
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
|
|
451
450
|
// ===== V2 Surface: Matrix Bridge governance overlay (CLI v0.134.0) =====
|
|
452
451
|
export const MX_ROOM_MATURITY_V2 = Object.freeze({
|
|
453
|
-
PENDING: "pending",
|
|
452
|
+
PENDING: "pending",
|
|
453
|
+
ACTIVE: "active",
|
|
454
|
+
MUTED: "muted",
|
|
455
|
+
ARCHIVED: "archived",
|
|
454
456
|
});
|
|
455
457
|
export const MX_MESSAGE_LIFECYCLE_V2 = Object.freeze({
|
|
456
|
-
QUEUED: "queued",
|
|
458
|
+
QUEUED: "queued",
|
|
459
|
+
SENDING: "sending",
|
|
460
|
+
DELIVERED: "delivered",
|
|
461
|
+
FAILED: "failed",
|
|
462
|
+
CANCELLED: "cancelled",
|
|
457
463
|
});
|
|
458
464
|
|
|
459
465
|
const _mxRoomTrans = new Map([
|
|
460
|
-
[
|
|
461
|
-
|
|
462
|
-
|
|
466
|
+
[
|
|
467
|
+
MX_ROOM_MATURITY_V2.PENDING,
|
|
468
|
+
new Set([MX_ROOM_MATURITY_V2.ACTIVE, MX_ROOM_MATURITY_V2.ARCHIVED]),
|
|
469
|
+
],
|
|
470
|
+
[
|
|
471
|
+
MX_ROOM_MATURITY_V2.ACTIVE,
|
|
472
|
+
new Set([MX_ROOM_MATURITY_V2.MUTED, MX_ROOM_MATURITY_V2.ARCHIVED]),
|
|
473
|
+
],
|
|
474
|
+
[
|
|
475
|
+
MX_ROOM_MATURITY_V2.MUTED,
|
|
476
|
+
new Set([MX_ROOM_MATURITY_V2.ACTIVE, MX_ROOM_MATURITY_V2.ARCHIVED]),
|
|
477
|
+
],
|
|
463
478
|
[MX_ROOM_MATURITY_V2.ARCHIVED, new Set()],
|
|
464
479
|
]);
|
|
465
480
|
const _mxRoomTerminal = new Set([MX_ROOM_MATURITY_V2.ARCHIVED]);
|
|
466
481
|
const _mxMsgTrans = new Map([
|
|
467
|
-
[
|
|
468
|
-
|
|
482
|
+
[
|
|
483
|
+
MX_MESSAGE_LIFECYCLE_V2.QUEUED,
|
|
484
|
+
new Set([
|
|
485
|
+
MX_MESSAGE_LIFECYCLE_V2.SENDING,
|
|
486
|
+
MX_MESSAGE_LIFECYCLE_V2.CANCELLED,
|
|
487
|
+
]),
|
|
488
|
+
],
|
|
489
|
+
[
|
|
490
|
+
MX_MESSAGE_LIFECYCLE_V2.SENDING,
|
|
491
|
+
new Set([
|
|
492
|
+
MX_MESSAGE_LIFECYCLE_V2.DELIVERED,
|
|
493
|
+
MX_MESSAGE_LIFECYCLE_V2.FAILED,
|
|
494
|
+
MX_MESSAGE_LIFECYCLE_V2.CANCELLED,
|
|
495
|
+
]),
|
|
496
|
+
],
|
|
469
497
|
[MX_MESSAGE_LIFECYCLE_V2.DELIVERED, new Set()],
|
|
470
498
|
[MX_MESSAGE_LIFECYCLE_V2.FAILED, new Set()],
|
|
471
499
|
[MX_MESSAGE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -478,21 +506,45 @@ let _mxMaxPendingPerRoom = 40;
|
|
|
478
506
|
let _mxRoomIdleMs = 24 * 60 * 60 * 1000;
|
|
479
507
|
let _mxMsgStuckMs = 3 * 60 * 1000;
|
|
480
508
|
|
|
481
|
-
function _mxPos(n, lbl) {
|
|
509
|
+
function _mxPos(n, lbl) {
|
|
510
|
+
const v = Math.floor(Number(n));
|
|
511
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
512
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
513
|
+
return v;
|
|
514
|
+
}
|
|
482
515
|
|
|
483
|
-
export function setMaxActiveMatrixRoomsPerOwnerV2(n) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
export function
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
export function
|
|
490
|
-
|
|
516
|
+
export function setMaxActiveMatrixRoomsPerOwnerV2(n) {
|
|
517
|
+
_mxMaxActivePerOwner = _mxPos(n, "maxActiveMatrixRoomsPerOwner");
|
|
518
|
+
}
|
|
519
|
+
export function getMaxActiveMatrixRoomsPerOwnerV2() {
|
|
520
|
+
return _mxMaxActivePerOwner;
|
|
521
|
+
}
|
|
522
|
+
export function setMaxPendingMatrixMessagesPerRoomV2(n) {
|
|
523
|
+
_mxMaxPendingPerRoom = _mxPos(n, "maxPendingMatrixMessagesPerRoom");
|
|
524
|
+
}
|
|
525
|
+
export function getMaxPendingMatrixMessagesPerRoomV2() {
|
|
526
|
+
return _mxMaxPendingPerRoom;
|
|
527
|
+
}
|
|
528
|
+
export function setMatrixRoomIdleMsV2(n) {
|
|
529
|
+
_mxRoomIdleMs = _mxPos(n, "matrixRoomIdleMs");
|
|
530
|
+
}
|
|
531
|
+
export function getMatrixRoomIdleMsV2() {
|
|
532
|
+
return _mxRoomIdleMs;
|
|
533
|
+
}
|
|
534
|
+
export function setMatrixMessageStuckMsV2(n) {
|
|
535
|
+
_mxMsgStuckMs = _mxPos(n, "matrixMessageStuckMs");
|
|
536
|
+
}
|
|
537
|
+
export function getMatrixMessageStuckMsV2() {
|
|
538
|
+
return _mxMsgStuckMs;
|
|
539
|
+
}
|
|
491
540
|
|
|
492
541
|
export function _resetStateMatrixBridgeV2() {
|
|
493
|
-
_mxRooms.clear();
|
|
494
|
-
|
|
495
|
-
|
|
542
|
+
_mxRooms.clear();
|
|
543
|
+
_mxMsgs.clear();
|
|
544
|
+
_mxMaxActivePerOwner = 20;
|
|
545
|
+
_mxMaxPendingPerRoom = 40;
|
|
546
|
+
_mxRoomIdleMs = 24 * 60 * 60 * 1000;
|
|
547
|
+
_mxMsgStuckMs = 3 * 60 * 1000;
|
|
496
548
|
}
|
|
497
549
|
|
|
498
550
|
export function registerMatrixRoomV2({ id, owner, alias, metadata } = {}) {
|
|
@@ -500,54 +552,236 @@ export function registerMatrixRoomV2({ id, owner, alias, metadata } = {}) {
|
|
|
500
552
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
501
553
|
if (_mxRooms.has(id)) throw new Error(`matrix room ${id} already registered`);
|
|
502
554
|
const now = Date.now();
|
|
503
|
-
const r = {
|
|
555
|
+
const r = {
|
|
556
|
+
id,
|
|
557
|
+
owner,
|
|
558
|
+
alias: alias || id,
|
|
559
|
+
status: MX_ROOM_MATURITY_V2.PENDING,
|
|
560
|
+
createdAt: now,
|
|
561
|
+
updatedAt: now,
|
|
562
|
+
activatedAt: null,
|
|
563
|
+
archivedAt: null,
|
|
564
|
+
lastTouchedAt: now,
|
|
565
|
+
metadata: { ...(metadata || {}) },
|
|
566
|
+
};
|
|
504
567
|
_mxRooms.set(id, r);
|
|
505
568
|
return { ...r, metadata: { ...r.metadata } };
|
|
506
569
|
}
|
|
507
|
-
function _mxCheckR(from, to) {
|
|
508
|
-
|
|
570
|
+
function _mxCheckR(from, to) {
|
|
571
|
+
const a = _mxRoomTrans.get(from);
|
|
572
|
+
if (!a || !a.has(to))
|
|
573
|
+
throw new Error(`invalid matrix room transition ${from} → ${to}`);
|
|
574
|
+
}
|
|
575
|
+
function _mxCountActive(owner) {
|
|
576
|
+
let n = 0;
|
|
577
|
+
for (const r of _mxRooms.values())
|
|
578
|
+
if (r.owner === owner && r.status === MX_ROOM_MATURITY_V2.ACTIVE) n++;
|
|
579
|
+
return n;
|
|
580
|
+
}
|
|
509
581
|
|
|
510
582
|
export function activateMatrixRoomV2(id) {
|
|
511
|
-
const r = _mxRooms.get(id);
|
|
583
|
+
const r = _mxRooms.get(id);
|
|
584
|
+
if (!r) throw new Error(`matrix room ${id} not found`);
|
|
512
585
|
_mxCheckR(r.status, MX_ROOM_MATURITY_V2.ACTIVE);
|
|
513
586
|
const recovery = r.status === MX_ROOM_MATURITY_V2.MUTED;
|
|
514
|
-
if (!recovery) {
|
|
515
|
-
|
|
587
|
+
if (!recovery) {
|
|
588
|
+
const a = _mxCountActive(r.owner);
|
|
589
|
+
if (a >= _mxMaxActivePerOwner)
|
|
590
|
+
throw new Error(
|
|
591
|
+
`max active matrix rooms per owner (${_mxMaxActivePerOwner}) reached for ${r.owner}`,
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
const now = Date.now();
|
|
595
|
+
r.status = MX_ROOM_MATURITY_V2.ACTIVE;
|
|
596
|
+
r.updatedAt = now;
|
|
597
|
+
r.lastTouchedAt = now;
|
|
598
|
+
if (!r.activatedAt) r.activatedAt = now;
|
|
599
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
600
|
+
}
|
|
601
|
+
export function muteMatrixRoomV2(id) {
|
|
602
|
+
const r = _mxRooms.get(id);
|
|
603
|
+
if (!r) throw new Error(`matrix room ${id} not found`);
|
|
604
|
+
_mxCheckR(r.status, MX_ROOM_MATURITY_V2.MUTED);
|
|
605
|
+
r.status = MX_ROOM_MATURITY_V2.MUTED;
|
|
606
|
+
r.updatedAt = Date.now();
|
|
516
607
|
return { ...r, metadata: { ...r.metadata } };
|
|
517
608
|
}
|
|
518
|
-
export function
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
609
|
+
export function archiveMatrixRoomV2(id) {
|
|
610
|
+
const r = _mxRooms.get(id);
|
|
611
|
+
if (!r) throw new Error(`matrix room ${id} not found`);
|
|
612
|
+
_mxCheckR(r.status, MX_ROOM_MATURITY_V2.ARCHIVED);
|
|
613
|
+
const now = Date.now();
|
|
614
|
+
r.status = MX_ROOM_MATURITY_V2.ARCHIVED;
|
|
615
|
+
r.updatedAt = now;
|
|
616
|
+
if (!r.archivedAt) r.archivedAt = now;
|
|
617
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
618
|
+
}
|
|
619
|
+
export function touchMatrixRoomV2(id) {
|
|
620
|
+
const r = _mxRooms.get(id);
|
|
621
|
+
if (!r) throw new Error(`matrix room ${id} not found`);
|
|
622
|
+
if (_mxRoomTerminal.has(r.status))
|
|
623
|
+
throw new Error(`cannot touch terminal matrix room ${id}`);
|
|
624
|
+
const now = Date.now();
|
|
625
|
+
r.lastTouchedAt = now;
|
|
626
|
+
r.updatedAt = now;
|
|
627
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
628
|
+
}
|
|
629
|
+
export function getMatrixRoomV2(id) {
|
|
630
|
+
const r = _mxRooms.get(id);
|
|
631
|
+
if (!r) return null;
|
|
632
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
633
|
+
}
|
|
634
|
+
export function listMatrixRoomsV2() {
|
|
635
|
+
return [..._mxRooms.values()].map((r) => ({
|
|
636
|
+
...r,
|
|
637
|
+
metadata: { ...r.metadata },
|
|
638
|
+
}));
|
|
639
|
+
}
|
|
523
640
|
|
|
524
|
-
function _mxCountPending(rid) {
|
|
641
|
+
function _mxCountPending(rid) {
|
|
642
|
+
let n = 0;
|
|
643
|
+
for (const m of _mxMsgs.values())
|
|
644
|
+
if (
|
|
645
|
+
m.roomId === rid &&
|
|
646
|
+
(m.status === MX_MESSAGE_LIFECYCLE_V2.QUEUED ||
|
|
647
|
+
m.status === MX_MESSAGE_LIFECYCLE_V2.SENDING)
|
|
648
|
+
)
|
|
649
|
+
n++;
|
|
650
|
+
return n;
|
|
651
|
+
}
|
|
525
652
|
|
|
526
653
|
export function createMatrixMessageV2({ id, roomId, body, metadata } = {}) {
|
|
527
654
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
528
|
-
if (!roomId || typeof roomId !== "string")
|
|
655
|
+
if (!roomId || typeof roomId !== "string")
|
|
656
|
+
throw new Error("roomId is required");
|
|
529
657
|
if (_mxMsgs.has(id)) throw new Error(`matrix message ${id} already exists`);
|
|
530
658
|
if (!_mxRooms.has(roomId)) throw new Error(`matrix room ${roomId} not found`);
|
|
531
659
|
const pending = _mxCountPending(roomId);
|
|
532
|
-
if (pending >= _mxMaxPendingPerRoom)
|
|
660
|
+
if (pending >= _mxMaxPendingPerRoom)
|
|
661
|
+
throw new Error(
|
|
662
|
+
`max pending matrix messages per room (${_mxMaxPendingPerRoom}) reached for ${roomId}`,
|
|
663
|
+
);
|
|
533
664
|
const now = Date.now();
|
|
534
|
-
const m = {
|
|
665
|
+
const m = {
|
|
666
|
+
id,
|
|
667
|
+
roomId,
|
|
668
|
+
body: body || "",
|
|
669
|
+
status: MX_MESSAGE_LIFECYCLE_V2.QUEUED,
|
|
670
|
+
createdAt: now,
|
|
671
|
+
updatedAt: now,
|
|
672
|
+
startedAt: null,
|
|
673
|
+
settledAt: null,
|
|
674
|
+
metadata: { ...(metadata || {}) },
|
|
675
|
+
};
|
|
535
676
|
_mxMsgs.set(id, m);
|
|
536
677
|
return { ...m, metadata: { ...m.metadata } };
|
|
537
678
|
}
|
|
538
|
-
function _mxCheckM(from, to) {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
export function
|
|
544
|
-
|
|
679
|
+
function _mxCheckM(from, to) {
|
|
680
|
+
const a = _mxMsgTrans.get(from);
|
|
681
|
+
if (!a || !a.has(to))
|
|
682
|
+
throw new Error(`invalid matrix message transition ${from} → ${to}`);
|
|
683
|
+
}
|
|
684
|
+
export function startMatrixMessageV2(id) {
|
|
685
|
+
const m = _mxMsgs.get(id);
|
|
686
|
+
if (!m) throw new Error(`matrix message ${id} not found`);
|
|
687
|
+
_mxCheckM(m.status, MX_MESSAGE_LIFECYCLE_V2.SENDING);
|
|
688
|
+
const now = Date.now();
|
|
689
|
+
m.status = MX_MESSAGE_LIFECYCLE_V2.SENDING;
|
|
690
|
+
m.updatedAt = now;
|
|
691
|
+
if (!m.startedAt) m.startedAt = now;
|
|
692
|
+
return { ...m, metadata: { ...m.metadata } };
|
|
693
|
+
}
|
|
694
|
+
export function deliverMatrixMessageV2(id) {
|
|
695
|
+
const m = _mxMsgs.get(id);
|
|
696
|
+
if (!m) throw new Error(`matrix message ${id} not found`);
|
|
697
|
+
_mxCheckM(m.status, MX_MESSAGE_LIFECYCLE_V2.DELIVERED);
|
|
698
|
+
const now = Date.now();
|
|
699
|
+
m.status = MX_MESSAGE_LIFECYCLE_V2.DELIVERED;
|
|
700
|
+
m.updatedAt = now;
|
|
701
|
+
if (!m.settledAt) m.settledAt = now;
|
|
702
|
+
return { ...m, metadata: { ...m.metadata } };
|
|
703
|
+
}
|
|
704
|
+
export function failMatrixMessageV2(id, reason) {
|
|
705
|
+
const m = _mxMsgs.get(id);
|
|
706
|
+
if (!m) throw new Error(`matrix message ${id} not found`);
|
|
707
|
+
_mxCheckM(m.status, MX_MESSAGE_LIFECYCLE_V2.FAILED);
|
|
708
|
+
const now = Date.now();
|
|
709
|
+
m.status = MX_MESSAGE_LIFECYCLE_V2.FAILED;
|
|
710
|
+
m.updatedAt = now;
|
|
711
|
+
if (!m.settledAt) m.settledAt = now;
|
|
712
|
+
if (reason) m.metadata.failReason = String(reason);
|
|
713
|
+
return { ...m, metadata: { ...m.metadata } };
|
|
714
|
+
}
|
|
715
|
+
export function cancelMatrixMessageV2(id, reason) {
|
|
716
|
+
const m = _mxMsgs.get(id);
|
|
717
|
+
if (!m) throw new Error(`matrix message ${id} not found`);
|
|
718
|
+
_mxCheckM(m.status, MX_MESSAGE_LIFECYCLE_V2.CANCELLED);
|
|
719
|
+
const now = Date.now();
|
|
720
|
+
m.status = MX_MESSAGE_LIFECYCLE_V2.CANCELLED;
|
|
721
|
+
m.updatedAt = now;
|
|
722
|
+
if (!m.settledAt) m.settledAt = now;
|
|
723
|
+
if (reason) m.metadata.cancelReason = String(reason);
|
|
724
|
+
return { ...m, metadata: { ...m.metadata } };
|
|
725
|
+
}
|
|
726
|
+
export function getMatrixMessageV2(id) {
|
|
727
|
+
const m = _mxMsgs.get(id);
|
|
728
|
+
if (!m) return null;
|
|
729
|
+
return { ...m, metadata: { ...m.metadata } };
|
|
730
|
+
}
|
|
731
|
+
export function listMatrixMessagesV2() {
|
|
732
|
+
return [..._mxMsgs.values()].map((m) => ({
|
|
733
|
+
...m,
|
|
734
|
+
metadata: { ...m.metadata },
|
|
735
|
+
}));
|
|
736
|
+
}
|
|
545
737
|
|
|
546
|
-
export function autoMuteIdleMatrixRoomsV2({ now } = {}) {
|
|
547
|
-
|
|
738
|
+
export function autoMuteIdleMatrixRoomsV2({ now } = {}) {
|
|
739
|
+
const t = now ?? Date.now();
|
|
740
|
+
const flipped = [];
|
|
741
|
+
for (const r of _mxRooms.values())
|
|
742
|
+
if (
|
|
743
|
+
r.status === MX_ROOM_MATURITY_V2.ACTIVE &&
|
|
744
|
+
t - r.lastTouchedAt >= _mxRoomIdleMs
|
|
745
|
+
) {
|
|
746
|
+
r.status = MX_ROOM_MATURITY_V2.MUTED;
|
|
747
|
+
r.updatedAt = t;
|
|
748
|
+
flipped.push(r.id);
|
|
749
|
+
}
|
|
750
|
+
return { flipped, count: flipped.length };
|
|
751
|
+
}
|
|
752
|
+
export function autoFailStuckMatrixMessagesV2({ now } = {}) {
|
|
753
|
+
const t = now ?? Date.now();
|
|
754
|
+
const flipped = [];
|
|
755
|
+
for (const m of _mxMsgs.values())
|
|
756
|
+
if (
|
|
757
|
+
m.status === MX_MESSAGE_LIFECYCLE_V2.SENDING &&
|
|
758
|
+
m.startedAt != null &&
|
|
759
|
+
t - m.startedAt >= _mxMsgStuckMs
|
|
760
|
+
) {
|
|
761
|
+
m.status = MX_MESSAGE_LIFECYCLE_V2.FAILED;
|
|
762
|
+
m.updatedAt = t;
|
|
763
|
+
if (!m.settledAt) m.settledAt = t;
|
|
764
|
+
m.metadata.failReason = "auto-fail-stuck";
|
|
765
|
+
flipped.push(m.id);
|
|
766
|
+
}
|
|
767
|
+
return { flipped, count: flipped.length };
|
|
768
|
+
}
|
|
548
769
|
|
|
549
770
|
export function getMatrixBridgeStatsV2() {
|
|
550
|
-
const roomsByStatus = {};
|
|
551
|
-
|
|
552
|
-
|
|
771
|
+
const roomsByStatus = {};
|
|
772
|
+
for (const s of Object.values(MX_ROOM_MATURITY_V2)) roomsByStatus[s] = 0;
|
|
773
|
+
for (const r of _mxRooms.values()) roomsByStatus[r.status]++;
|
|
774
|
+
const msgsByStatus = {};
|
|
775
|
+
for (const s of Object.values(MX_MESSAGE_LIFECYCLE_V2)) msgsByStatus[s] = 0;
|
|
776
|
+
for (const m of _mxMsgs.values()) msgsByStatus[m.status]++;
|
|
777
|
+
return {
|
|
778
|
+
totalRoomsV2: _mxRooms.size,
|
|
779
|
+
totalMessagesV2: _mxMsgs.size,
|
|
780
|
+
maxActiveMatrixRoomsPerOwner: _mxMaxActivePerOwner,
|
|
781
|
+
maxPendingMatrixMessagesPerRoom: _mxMaxPendingPerRoom,
|
|
782
|
+
matrixRoomIdleMs: _mxRoomIdleMs,
|
|
783
|
+
matrixMessageStuckMs: _mxMsgStuckMs,
|
|
784
|
+
roomsByStatus,
|
|
785
|
+
msgsByStatus,
|
|
786
|
+
};
|
|
553
787
|
}
|