chainlesschain 0.66.0 → 0.132.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/bin/chainlesschain.js +0 -0
- package/package.json +1 -1
- package/src/commands/a2a.js +380 -0
- package/src/commands/agent-network.js +254 -1
- package/src/commands/audit.js +302 -0
- package/src/commands/automation.js +271 -1
- package/src/commands/bi.js +348 -0
- package/src/commands/codegen.js +224 -0
- package/src/commands/collab.js +341 -0
- package/src/commands/compliance.js +1035 -0
- package/src/commands/cowork.js +221 -0
- package/src/commands/crosschain.js +218 -0
- package/src/commands/dbevo.js +284 -0
- package/src/commands/dev.js +252 -0
- package/src/commands/did.js +358 -0
- package/src/commands/dlp.js +341 -0
- package/src/commands/encrypt.js +341 -0
- package/src/commands/evomap.js +394 -0
- package/src/commands/export.js +256 -1
- package/src/commands/federation.js +283 -0
- package/src/commands/fusion.js +258 -0
- package/src/commands/governance.js +325 -0
- package/src/commands/hardening.js +411 -0
- package/src/commands/hook.js +148 -0
- package/src/commands/import.js +252 -0
- package/src/commands/incentive.js +322 -0
- package/src/commands/inference.js +318 -0
- package/src/commands/infra.js +244 -0
- package/src/commands/instinct.js +260 -0
- package/src/commands/ipfs.js +318 -0
- package/src/commands/kg.js +387 -0
- package/src/commands/llm.js +263 -0
- package/src/commands/lowcode.js +356 -0
- package/src/commands/marketplace.js +256 -0
- package/src/commands/mcp.js +221 -0
- package/src/commands/memory.js +248 -0
- package/src/commands/multimodal.js +296 -0
- package/src/commands/nlprog.js +356 -0
- package/src/commands/note.js +244 -0
- package/src/commands/ops.js +354 -0
- package/src/commands/orchestrate.js +166 -0
- package/src/commands/org.js +277 -0
- package/src/commands/p2p.js +390 -0
- package/src/commands/perception.js +290 -0
- package/src/commands/permmem.js +251 -0
- package/src/commands/plugin-ecosystem.js +273 -0
- package/src/commands/pqc.js +393 -0
- package/src/commands/privacy.js +321 -0
- package/src/commands/quantization.js +351 -0
- package/src/commands/rcache.js +271 -0
- package/src/commands/recommend.js +340 -0
- package/src/commands/reputation.js +261 -0
- package/src/commands/runtime.js +307 -0
- package/src/commands/scim.js +262 -0
- package/src/commands/session.js +258 -0
- package/src/commands/siem.js +246 -0
- package/src/commands/skill.js +267 -1
- package/src/commands/sla.js +259 -0
- package/src/commands/social.js +256 -0
- package/src/commands/sso.js +186 -1
- package/src/commands/stress.js +230 -0
- package/src/commands/sync.js +256 -0
- package/src/commands/tech.js +338 -0
- package/src/commands/tenant.js +351 -0
- package/src/commands/terraform.js +245 -0
- package/src/commands/tokens.js +269 -0
- package/src/commands/trust.js +249 -0
- package/src/commands/wallet.js +277 -0
- package/src/commands/workflow.js +171 -0
- package/src/commands/zkp.js +335 -0
- package/src/index.js +4 -0
- package/src/lib/a2a-protocol.js +451 -0
- package/src/lib/agent-coordinator.js +325 -0
- package/src/lib/agent-network.js +387 -0
- package/src/lib/agent-router.js +395 -0
- package/src/lib/aiops.js +478 -0
- package/src/lib/app-builder.js +239 -0
- package/src/lib/audit-logger.js +379 -0
- package/src/lib/automation-engine.js +330 -0
- package/src/lib/autonomous-developer.js +350 -0
- package/src/lib/bi-engine.js +338 -0
- package/src/lib/code-agent.js +323 -0
- package/src/lib/collaboration-governance.js +364 -0
- package/src/lib/community-governance.js +436 -0
- package/src/lib/compliance-manager.js +434 -0
- package/src/lib/content-recommendation.js +469 -0
- package/src/lib/cross-chain.js +345 -0
- package/src/lib/crypto-manager.js +350 -0
- package/src/lib/dbevo.js +338 -0
- package/src/lib/decentral-infra.js +340 -0
- package/src/lib/did-manager.js +367 -0
- package/src/lib/dlp-engine.js +389 -0
- package/src/lib/evomap-federation.js +177 -0
- package/src/lib/evomap-governance.js +276 -0
- package/src/lib/federation-hardening.js +259 -0
- package/src/lib/hardening-manager.js +348 -0
- package/src/lib/hook-manager.js +380 -0
- package/src/lib/inference-network.js +330 -0
- package/src/lib/instinct-manager.js +332 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +381 -0
- package/src/lib/knowledge-graph.js +432 -0
- package/src/lib/knowledge-importer.js +379 -0
- package/src/lib/llm-providers.js +391 -0
- package/src/lib/mcp-registry.js +333 -0
- package/src/lib/memory-manager.js +330 -0
- package/src/lib/multimodal.js +346 -0
- package/src/lib/nl-programming.js +343 -0
- package/src/lib/note-versioning.js +327 -0
- package/src/lib/org-manager.js +323 -0
- package/src/lib/p2p-manager.js +387 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +4 -1
- package/src/lib/permanent-memory.js +320 -0
- package/src/lib/plugin-ecosystem.js +377 -0
- package/src/lib/pqc-manager.js +368 -0
- package/src/lib/privacy-computing.js +427 -0
- package/src/lib/protocol-fusion.js +417 -0
- package/src/lib/quantization.js +325 -0
- package/src/lib/reputation-optimizer.js +299 -0
- package/src/lib/response-cache.js +327 -0
- package/src/lib/scim-manager.js +329 -0
- package/src/lib/session-manager.js +329 -0
- package/src/lib/siem-exporter.js +333 -0
- package/src/lib/skill-loader.js +377 -0
- package/src/lib/skill-marketplace.js +325 -0
- package/src/lib/sla-manager.js +275 -0
- package/src/lib/social-manager.js +326 -0
- package/src/lib/sso-manager.js +332 -0
- package/src/lib/stress-tester.js +330 -0
- package/src/lib/sync-manager.js +326 -0
- package/src/lib/tech-learning-engine.js +369 -0
- package/src/lib/tenant-saas.js +460 -0
- package/src/lib/terraform-manager.js +363 -0
- package/src/lib/threat-intel.js +335 -0
- package/src/lib/token-incentive.js +293 -0
- package/src/lib/token-tracker.js +329 -0
- package/src/lib/trust-security.js +390 -0
- package/src/lib/ueba.js +389 -0
- package/src/lib/universal-runtime.js +325 -0
- package/src/lib/wallet-manager.js +326 -0
- package/src/lib/workflow-engine.js +322 -0
- package/src/lib/zkp-engine.js +274 -0
package/src/lib/agent-router.js
CHANGED
|
@@ -395,3 +395,398 @@ export class AgentRouter extends EventEmitter {
|
|
|
395
395
|
}));
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
|
+
|
|
399
|
+
// ===== V2 Surface: Agent Router governance overlay (CLI v0.132.0) =====
|
|
400
|
+
// In-memory governance for router profiles + dispatch lifecycle, independent of
|
|
401
|
+
// the AgentRouter class above (legacy ClaudeCodePool/createChatFn untouched).
|
|
402
|
+
|
|
403
|
+
export const ROUTER_PROFILE_MATURITY_V2 = Object.freeze({
|
|
404
|
+
PENDING: "pending",
|
|
405
|
+
ACTIVE: "active",
|
|
406
|
+
DEGRADED: "degraded",
|
|
407
|
+
RETIRED: "retired",
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
export const ROUTER_DISPATCH_LIFECYCLE_V2 = Object.freeze({
|
|
411
|
+
QUEUED: "queued",
|
|
412
|
+
DISPATCHING: "dispatching",
|
|
413
|
+
COMPLETED: "completed",
|
|
414
|
+
FAILED: "failed",
|
|
415
|
+
CANCELLED: "cancelled",
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
const _profileTransitionsV2 = new Map([
|
|
419
|
+
[
|
|
420
|
+
ROUTER_PROFILE_MATURITY_V2.PENDING,
|
|
421
|
+
new Set([
|
|
422
|
+
ROUTER_PROFILE_MATURITY_V2.ACTIVE,
|
|
423
|
+
ROUTER_PROFILE_MATURITY_V2.RETIRED,
|
|
424
|
+
]),
|
|
425
|
+
],
|
|
426
|
+
[
|
|
427
|
+
ROUTER_PROFILE_MATURITY_V2.ACTIVE,
|
|
428
|
+
new Set([
|
|
429
|
+
ROUTER_PROFILE_MATURITY_V2.DEGRADED,
|
|
430
|
+
ROUTER_PROFILE_MATURITY_V2.RETIRED,
|
|
431
|
+
]),
|
|
432
|
+
],
|
|
433
|
+
[
|
|
434
|
+
ROUTER_PROFILE_MATURITY_V2.DEGRADED,
|
|
435
|
+
new Set([
|
|
436
|
+
ROUTER_PROFILE_MATURITY_V2.ACTIVE,
|
|
437
|
+
ROUTER_PROFILE_MATURITY_V2.RETIRED,
|
|
438
|
+
]),
|
|
439
|
+
],
|
|
440
|
+
[ROUTER_PROFILE_MATURITY_V2.RETIRED, new Set()],
|
|
441
|
+
]);
|
|
442
|
+
const _profileTerminalV2 = new Set([ROUTER_PROFILE_MATURITY_V2.RETIRED]);
|
|
443
|
+
|
|
444
|
+
const _dispatchTransitionsV2 = new Map([
|
|
445
|
+
[
|
|
446
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.QUEUED,
|
|
447
|
+
new Set([
|
|
448
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.DISPATCHING,
|
|
449
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.CANCELLED,
|
|
450
|
+
]),
|
|
451
|
+
],
|
|
452
|
+
[
|
|
453
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.DISPATCHING,
|
|
454
|
+
new Set([
|
|
455
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.COMPLETED,
|
|
456
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.FAILED,
|
|
457
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.CANCELLED,
|
|
458
|
+
]),
|
|
459
|
+
],
|
|
460
|
+
[ROUTER_DISPATCH_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
461
|
+
[ROUTER_DISPATCH_LIFECYCLE_V2.FAILED, new Set()],
|
|
462
|
+
[ROUTER_DISPATCH_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
463
|
+
]);
|
|
464
|
+
const _dispatchTerminalV2 = new Set([
|
|
465
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.COMPLETED,
|
|
466
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.FAILED,
|
|
467
|
+
ROUTER_DISPATCH_LIFECYCLE_V2.CANCELLED,
|
|
468
|
+
]);
|
|
469
|
+
|
|
470
|
+
const _profilesV2 = new Map();
|
|
471
|
+
const _dispatchesV2 = new Map();
|
|
472
|
+
let _maxActiveProfilesPerOwnerRouterV2 = 8;
|
|
473
|
+
let _maxPendingDispatchesPerProfileV2 = 16;
|
|
474
|
+
let _profileIdleMsRouterV2 = 6 * 60 * 60 * 1000;
|
|
475
|
+
let _dispatchStuckMsV2 = 5 * 60 * 1000;
|
|
476
|
+
|
|
477
|
+
function _routerPosIntV2(n, label) {
|
|
478
|
+
const v = Math.floor(Number(n));
|
|
479
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
480
|
+
throw new Error(`${label} must be positive integer`);
|
|
481
|
+
return v;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export function setMaxActiveProfilesPerOwnerRouterV2(n) {
|
|
485
|
+
_maxActiveProfilesPerOwnerRouterV2 = _routerPosIntV2(
|
|
486
|
+
n,
|
|
487
|
+
"maxActiveProfilesPerOwner",
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
export function getMaxActiveProfilesPerOwnerRouterV2() {
|
|
491
|
+
return _maxActiveProfilesPerOwnerRouterV2;
|
|
492
|
+
}
|
|
493
|
+
export function setMaxPendingDispatchesPerProfileV2(n) {
|
|
494
|
+
_maxPendingDispatchesPerProfileV2 = _routerPosIntV2(
|
|
495
|
+
n,
|
|
496
|
+
"maxPendingDispatchesPerProfile",
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
export function getMaxPendingDispatchesPerProfileV2() {
|
|
500
|
+
return _maxPendingDispatchesPerProfileV2;
|
|
501
|
+
}
|
|
502
|
+
export function setProfileIdleMsRouterV2(n) {
|
|
503
|
+
_profileIdleMsRouterV2 = _routerPosIntV2(n, "profileIdleMs");
|
|
504
|
+
}
|
|
505
|
+
export function getProfileIdleMsRouterV2() {
|
|
506
|
+
return _profileIdleMsRouterV2;
|
|
507
|
+
}
|
|
508
|
+
export function setDispatchStuckMsV2(n) {
|
|
509
|
+
_dispatchStuckMsV2 = _routerPosIntV2(n, "dispatchStuckMs");
|
|
510
|
+
}
|
|
511
|
+
export function getDispatchStuckMsV2() {
|
|
512
|
+
return _dispatchStuckMsV2;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export function _resetStateAgentRouterV2() {
|
|
516
|
+
_profilesV2.clear();
|
|
517
|
+
_dispatchesV2.clear();
|
|
518
|
+
_maxActiveProfilesPerOwnerRouterV2 = 8;
|
|
519
|
+
_maxPendingDispatchesPerProfileV2 = 16;
|
|
520
|
+
_profileIdleMsRouterV2 = 6 * 60 * 60 * 1000;
|
|
521
|
+
_dispatchStuckMsV2 = 5 * 60 * 1000;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export function registerRouterProfileV2({
|
|
525
|
+
id,
|
|
526
|
+
owner,
|
|
527
|
+
strategy,
|
|
528
|
+
metadata,
|
|
529
|
+
} = {}) {
|
|
530
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
531
|
+
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
532
|
+
if (_profilesV2.has(id)) throw new Error(`profile ${id} already registered`);
|
|
533
|
+
const now = Date.now();
|
|
534
|
+
const profile = {
|
|
535
|
+
id,
|
|
536
|
+
owner,
|
|
537
|
+
strategy: strategy || "round-robin",
|
|
538
|
+
status: ROUTER_PROFILE_MATURITY_V2.PENDING,
|
|
539
|
+
createdAt: now,
|
|
540
|
+
updatedAt: now,
|
|
541
|
+
activatedAt: null,
|
|
542
|
+
retiredAt: null,
|
|
543
|
+
lastTouchedAt: now,
|
|
544
|
+
metadata: { ...(metadata || {}) },
|
|
545
|
+
};
|
|
546
|
+
_profilesV2.set(id, profile);
|
|
547
|
+
return { ...profile, metadata: { ...profile.metadata } };
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function _routerCheckTransition(from, to) {
|
|
551
|
+
const allowed = _profileTransitionsV2.get(from);
|
|
552
|
+
if (!allowed || !allowed.has(to))
|
|
553
|
+
throw new Error(`invalid profile transition ${from} → ${to}`);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function _countActiveProfilesByOwner(owner) {
|
|
557
|
+
let n = 0;
|
|
558
|
+
for (const p of _profilesV2.values()) {
|
|
559
|
+
if (p.owner === owner && p.status === ROUTER_PROFILE_MATURITY_V2.ACTIVE)
|
|
560
|
+
n++;
|
|
561
|
+
}
|
|
562
|
+
return n;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export function activateRouterProfileV2(id) {
|
|
566
|
+
const p = _profilesV2.get(id);
|
|
567
|
+
if (!p) throw new Error(`profile ${id} not found`);
|
|
568
|
+
_routerCheckTransition(p.status, ROUTER_PROFILE_MATURITY_V2.ACTIVE);
|
|
569
|
+
const isRecovery = p.status === ROUTER_PROFILE_MATURITY_V2.DEGRADED;
|
|
570
|
+
if (!isRecovery) {
|
|
571
|
+
const active = _countActiveProfilesByOwner(p.owner);
|
|
572
|
+
if (active >= _maxActiveProfilesPerOwnerRouterV2) {
|
|
573
|
+
throw new Error(
|
|
574
|
+
`max active profiles per owner (${_maxActiveProfilesPerOwnerRouterV2}) reached for ${p.owner}`,
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const now = Date.now();
|
|
579
|
+
p.status = ROUTER_PROFILE_MATURITY_V2.ACTIVE;
|
|
580
|
+
p.updatedAt = now;
|
|
581
|
+
p.lastTouchedAt = now;
|
|
582
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
583
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
export function degradeRouterProfileV2(id) {
|
|
587
|
+
const p = _profilesV2.get(id);
|
|
588
|
+
if (!p) throw new Error(`profile ${id} not found`);
|
|
589
|
+
_routerCheckTransition(p.status, ROUTER_PROFILE_MATURITY_V2.DEGRADED);
|
|
590
|
+
const now = Date.now();
|
|
591
|
+
p.status = ROUTER_PROFILE_MATURITY_V2.DEGRADED;
|
|
592
|
+
p.updatedAt = now;
|
|
593
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export function retireRouterProfileV2(id) {
|
|
597
|
+
const p = _profilesV2.get(id);
|
|
598
|
+
if (!p) throw new Error(`profile ${id} not found`);
|
|
599
|
+
_routerCheckTransition(p.status, ROUTER_PROFILE_MATURITY_V2.RETIRED);
|
|
600
|
+
const now = Date.now();
|
|
601
|
+
p.status = ROUTER_PROFILE_MATURITY_V2.RETIRED;
|
|
602
|
+
p.updatedAt = now;
|
|
603
|
+
if (!p.retiredAt) p.retiredAt = now;
|
|
604
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export function touchRouterProfileV2(id) {
|
|
608
|
+
const p = _profilesV2.get(id);
|
|
609
|
+
if (!p) throw new Error(`profile ${id} not found`);
|
|
610
|
+
if (_profileTerminalV2.has(p.status))
|
|
611
|
+
throw new Error(`cannot touch terminal profile ${id}`);
|
|
612
|
+
const now = Date.now();
|
|
613
|
+
p.lastTouchedAt = now;
|
|
614
|
+
p.updatedAt = now;
|
|
615
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export function getRouterProfileV2(id) {
|
|
619
|
+
const p = _profilesV2.get(id);
|
|
620
|
+
if (!p) return null;
|
|
621
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export function listRouterProfilesV2() {
|
|
625
|
+
return [..._profilesV2.values()].map((p) => ({
|
|
626
|
+
...p,
|
|
627
|
+
metadata: { ...p.metadata },
|
|
628
|
+
}));
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function _countPendingDispatchesByProfile(profileId) {
|
|
632
|
+
let n = 0;
|
|
633
|
+
for (const d of _dispatchesV2.values()) {
|
|
634
|
+
if (
|
|
635
|
+
d.profileId === profileId &&
|
|
636
|
+
(d.status === ROUTER_DISPATCH_LIFECYCLE_V2.QUEUED ||
|
|
637
|
+
d.status === ROUTER_DISPATCH_LIFECYCLE_V2.DISPATCHING)
|
|
638
|
+
)
|
|
639
|
+
n++;
|
|
640
|
+
}
|
|
641
|
+
return n;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export function createDispatchV2({ id, profileId, task, metadata } = {}) {
|
|
645
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
646
|
+
if (!profileId || typeof profileId !== "string")
|
|
647
|
+
throw new Error("profileId is required");
|
|
648
|
+
if (_dispatchesV2.has(id)) throw new Error(`dispatch ${id} already exists`);
|
|
649
|
+
const profile = _profilesV2.get(profileId);
|
|
650
|
+
if (!profile) throw new Error(`profile ${profileId} not found`);
|
|
651
|
+
const pending = _countPendingDispatchesByProfile(profileId);
|
|
652
|
+
if (pending >= _maxPendingDispatchesPerProfileV2) {
|
|
653
|
+
throw new Error(
|
|
654
|
+
`max pending dispatches per profile (${_maxPendingDispatchesPerProfileV2}) reached for ${profileId}`,
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const now = Date.now();
|
|
658
|
+
const d = {
|
|
659
|
+
id,
|
|
660
|
+
profileId,
|
|
661
|
+
task: task || "",
|
|
662
|
+
status: ROUTER_DISPATCH_LIFECYCLE_V2.QUEUED,
|
|
663
|
+
createdAt: now,
|
|
664
|
+
updatedAt: now,
|
|
665
|
+
dispatchedAt: null,
|
|
666
|
+
settledAt: null,
|
|
667
|
+
metadata: { ...(metadata || {}) },
|
|
668
|
+
};
|
|
669
|
+
_dispatchesV2.set(id, d);
|
|
670
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function _dispatchCheckTransition(from, to) {
|
|
674
|
+
const allowed = _dispatchTransitionsV2.get(from);
|
|
675
|
+
if (!allowed || !allowed.has(to))
|
|
676
|
+
throw new Error(`invalid dispatch transition ${from} → ${to}`);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
export function dispatchDispatchV2(id) {
|
|
680
|
+
const d = _dispatchesV2.get(id);
|
|
681
|
+
if (!d) throw new Error(`dispatch ${id} not found`);
|
|
682
|
+
_dispatchCheckTransition(d.status, ROUTER_DISPATCH_LIFECYCLE_V2.DISPATCHING);
|
|
683
|
+
const now = Date.now();
|
|
684
|
+
d.status = ROUTER_DISPATCH_LIFECYCLE_V2.DISPATCHING;
|
|
685
|
+
d.updatedAt = now;
|
|
686
|
+
if (!d.dispatchedAt) d.dispatchedAt = now;
|
|
687
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
export function completeDispatchV2(id) {
|
|
691
|
+
const d = _dispatchesV2.get(id);
|
|
692
|
+
if (!d) throw new Error(`dispatch ${id} not found`);
|
|
693
|
+
_dispatchCheckTransition(d.status, ROUTER_DISPATCH_LIFECYCLE_V2.COMPLETED);
|
|
694
|
+
const now = Date.now();
|
|
695
|
+
d.status = ROUTER_DISPATCH_LIFECYCLE_V2.COMPLETED;
|
|
696
|
+
d.updatedAt = now;
|
|
697
|
+
if (!d.settledAt) d.settledAt = now;
|
|
698
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
export function failDispatchV2(id, reason) {
|
|
702
|
+
const d = _dispatchesV2.get(id);
|
|
703
|
+
if (!d) throw new Error(`dispatch ${id} not found`);
|
|
704
|
+
_dispatchCheckTransition(d.status, ROUTER_DISPATCH_LIFECYCLE_V2.FAILED);
|
|
705
|
+
const now = Date.now();
|
|
706
|
+
d.status = ROUTER_DISPATCH_LIFECYCLE_V2.FAILED;
|
|
707
|
+
d.updatedAt = now;
|
|
708
|
+
if (!d.settledAt) d.settledAt = now;
|
|
709
|
+
if (reason) d.metadata.failReason = String(reason);
|
|
710
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
export function cancelDispatchV2(id, reason) {
|
|
714
|
+
const d = _dispatchesV2.get(id);
|
|
715
|
+
if (!d) throw new Error(`dispatch ${id} not found`);
|
|
716
|
+
_dispatchCheckTransition(d.status, ROUTER_DISPATCH_LIFECYCLE_V2.CANCELLED);
|
|
717
|
+
const now = Date.now();
|
|
718
|
+
d.status = ROUTER_DISPATCH_LIFECYCLE_V2.CANCELLED;
|
|
719
|
+
d.updatedAt = now;
|
|
720
|
+
if (!d.settledAt) d.settledAt = now;
|
|
721
|
+
if (reason) d.metadata.cancelReason = String(reason);
|
|
722
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
export function getDispatchV2(id) {
|
|
726
|
+
const d = _dispatchesV2.get(id);
|
|
727
|
+
if (!d) return null;
|
|
728
|
+
return { ...d, metadata: { ...d.metadata } };
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
export function listDispatchesV2() {
|
|
732
|
+
return [..._dispatchesV2.values()].map((d) => ({
|
|
733
|
+
...d,
|
|
734
|
+
metadata: { ...d.metadata },
|
|
735
|
+
}));
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
export function autoDegradeIdleProfilesRouterV2({ now } = {}) {
|
|
739
|
+
const t = now ?? Date.now();
|
|
740
|
+
const flipped = [];
|
|
741
|
+
for (const p of _profilesV2.values()) {
|
|
742
|
+
if (
|
|
743
|
+
p.status === ROUTER_PROFILE_MATURITY_V2.ACTIVE &&
|
|
744
|
+
t - p.lastTouchedAt >= _profileIdleMsRouterV2
|
|
745
|
+
) {
|
|
746
|
+
p.status = ROUTER_PROFILE_MATURITY_V2.DEGRADED;
|
|
747
|
+
p.updatedAt = t;
|
|
748
|
+
flipped.push(p.id);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
return { flipped, count: flipped.length };
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
export function autoFailStuckDispatchesV2({ now } = {}) {
|
|
755
|
+
const t = now ?? Date.now();
|
|
756
|
+
const flipped = [];
|
|
757
|
+
for (const d of _dispatchesV2.values()) {
|
|
758
|
+
if (
|
|
759
|
+
d.status === ROUTER_DISPATCH_LIFECYCLE_V2.DISPATCHING &&
|
|
760
|
+
d.dispatchedAt != null &&
|
|
761
|
+
t - d.dispatchedAt >= _dispatchStuckMsV2
|
|
762
|
+
) {
|
|
763
|
+
d.status = ROUTER_DISPATCH_LIFECYCLE_V2.FAILED;
|
|
764
|
+
d.updatedAt = t;
|
|
765
|
+
if (!d.settledAt) d.settledAt = t;
|
|
766
|
+
d.metadata.failReason = "auto-fail-stuck";
|
|
767
|
+
flipped.push(d.id);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return { flipped, count: flipped.length };
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export function getAgentRouterStatsV2() {
|
|
774
|
+
const profilesByStatus = {};
|
|
775
|
+
for (const s of Object.values(ROUTER_PROFILE_MATURITY_V2))
|
|
776
|
+
profilesByStatus[s] = 0;
|
|
777
|
+
for (const p of _profilesV2.values()) profilesByStatus[p.status]++;
|
|
778
|
+
const dispatchesByStatus = {};
|
|
779
|
+
for (const s of Object.values(ROUTER_DISPATCH_LIFECYCLE_V2))
|
|
780
|
+
dispatchesByStatus[s] = 0;
|
|
781
|
+
for (const d of _dispatchesV2.values()) dispatchesByStatus[d.status]++;
|
|
782
|
+
return {
|
|
783
|
+
totalProfilesV2: _profilesV2.size,
|
|
784
|
+
totalDispatchesV2: _dispatchesV2.size,
|
|
785
|
+
maxActiveProfilesPerOwner: _maxActiveProfilesPerOwnerRouterV2,
|
|
786
|
+
maxPendingDispatchesPerProfile: _maxPendingDispatchesPerProfileV2,
|
|
787
|
+
profileIdleMs: _profileIdleMsRouterV2,
|
|
788
|
+
dispatchStuckMs: _dispatchStuckMsV2,
|
|
789
|
+
profilesByStatus,
|
|
790
|
+
dispatchesByStatus,
|
|
791
|
+
};
|
|
792
|
+
}
|