chainlesschain 0.143.0 → 0.152.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 +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -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/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -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-recommendation.js +351 -0
- 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-share.js +338 -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/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- 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/federation-hardening.js +340 -0
- 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/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- 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/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -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-manager.js +334 -0
- 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-loader.js +334 -0
- 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/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/orchestrator.js
CHANGED
|
@@ -437,25 +437,62 @@ function _extractChangedFiles(output) {
|
|
|
437
437
|
return matches.map((m) => m.split(/:\s+/)[1]).filter(Boolean);
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
-
|
|
441
440
|
// ===== V2 Surface: Orchestrator governance overlay (CLI v0.140.0) =====
|
|
442
441
|
export const ORCH_PROFILE_MATURITY_V2 = Object.freeze({
|
|
443
|
-
PENDING: "pending",
|
|
442
|
+
PENDING: "pending",
|
|
443
|
+
ACTIVE: "active",
|
|
444
|
+
PAUSED: "paused",
|
|
445
|
+
RETIRED: "retired",
|
|
444
446
|
});
|
|
445
447
|
export const ORCH_TASK_LIFECYCLE_V2 = Object.freeze({
|
|
446
|
-
QUEUED: "queued",
|
|
448
|
+
QUEUED: "queued",
|
|
449
|
+
DISPATCHING: "dispatching",
|
|
450
|
+
COMPLETED: "completed",
|
|
451
|
+
FAILED: "failed",
|
|
452
|
+
CANCELLED: "cancelled",
|
|
447
453
|
});
|
|
448
454
|
|
|
449
455
|
const _opTrans = new Map([
|
|
450
|
-
[
|
|
451
|
-
|
|
452
|
-
|
|
456
|
+
[
|
|
457
|
+
ORCH_PROFILE_MATURITY_V2.PENDING,
|
|
458
|
+
new Set([
|
|
459
|
+
ORCH_PROFILE_MATURITY_V2.ACTIVE,
|
|
460
|
+
ORCH_PROFILE_MATURITY_V2.RETIRED,
|
|
461
|
+
]),
|
|
462
|
+
],
|
|
463
|
+
[
|
|
464
|
+
ORCH_PROFILE_MATURITY_V2.ACTIVE,
|
|
465
|
+
new Set([
|
|
466
|
+
ORCH_PROFILE_MATURITY_V2.PAUSED,
|
|
467
|
+
ORCH_PROFILE_MATURITY_V2.RETIRED,
|
|
468
|
+
]),
|
|
469
|
+
],
|
|
470
|
+
[
|
|
471
|
+
ORCH_PROFILE_MATURITY_V2.PAUSED,
|
|
472
|
+
new Set([
|
|
473
|
+
ORCH_PROFILE_MATURITY_V2.ACTIVE,
|
|
474
|
+
ORCH_PROFILE_MATURITY_V2.RETIRED,
|
|
475
|
+
]),
|
|
476
|
+
],
|
|
453
477
|
[ORCH_PROFILE_MATURITY_V2.RETIRED, new Set()],
|
|
454
478
|
]);
|
|
455
479
|
const _opTerminal = new Set([ORCH_PROFILE_MATURITY_V2.RETIRED]);
|
|
456
480
|
const _otTrans = new Map([
|
|
457
|
-
[
|
|
458
|
-
|
|
481
|
+
[
|
|
482
|
+
ORCH_TASK_LIFECYCLE_V2.QUEUED,
|
|
483
|
+
new Set([
|
|
484
|
+
ORCH_TASK_LIFECYCLE_V2.DISPATCHING,
|
|
485
|
+
ORCH_TASK_LIFECYCLE_V2.CANCELLED,
|
|
486
|
+
]),
|
|
487
|
+
],
|
|
488
|
+
[
|
|
489
|
+
ORCH_TASK_LIFECYCLE_V2.DISPATCHING,
|
|
490
|
+
new Set([
|
|
491
|
+
ORCH_TASK_LIFECYCLE_V2.COMPLETED,
|
|
492
|
+
ORCH_TASK_LIFECYCLE_V2.FAILED,
|
|
493
|
+
ORCH_TASK_LIFECYCLE_V2.CANCELLED,
|
|
494
|
+
]),
|
|
495
|
+
],
|
|
459
496
|
[ORCH_TASK_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
460
497
|
[ORCH_TASK_LIFECYCLE_V2.FAILED, new Set()],
|
|
461
498
|
[ORCH_TASK_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -468,21 +505,45 @@ let _opMaxPendingTasksPerProfile = 12;
|
|
|
468
505
|
let _opIdleMs = 14 * 24 * 60 * 60 * 1000;
|
|
469
506
|
let _otStuckMs = 15 * 60 * 1000;
|
|
470
507
|
|
|
471
|
-
function _opPos(n, lbl) {
|
|
508
|
+
function _opPos(n, lbl) {
|
|
509
|
+
const v = Math.floor(Number(n));
|
|
510
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
511
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
512
|
+
return v;
|
|
513
|
+
}
|
|
472
514
|
|
|
473
|
-
export function setMaxActiveOrchProfilesPerOwnerV2(n) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
export function
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
export function
|
|
480
|
-
|
|
515
|
+
export function setMaxActiveOrchProfilesPerOwnerV2(n) {
|
|
516
|
+
_opMaxActivePerOwner = _opPos(n, "maxActiveOrchProfilesPerOwner");
|
|
517
|
+
}
|
|
518
|
+
export function getMaxActiveOrchProfilesPerOwnerV2() {
|
|
519
|
+
return _opMaxActivePerOwner;
|
|
520
|
+
}
|
|
521
|
+
export function setMaxPendingOrchTasksPerProfileV2(n) {
|
|
522
|
+
_opMaxPendingTasksPerProfile = _opPos(n, "maxPendingOrchTasksPerProfile");
|
|
523
|
+
}
|
|
524
|
+
export function getMaxPendingOrchTasksPerProfileV2() {
|
|
525
|
+
return _opMaxPendingTasksPerProfile;
|
|
526
|
+
}
|
|
527
|
+
export function setOrchProfileIdleMsV2(n) {
|
|
528
|
+
_opIdleMs = _opPos(n, "orchProfileIdleMs");
|
|
529
|
+
}
|
|
530
|
+
export function getOrchProfileIdleMsV2() {
|
|
531
|
+
return _opIdleMs;
|
|
532
|
+
}
|
|
533
|
+
export function setOrchTaskStuckMsV2(n) {
|
|
534
|
+
_otStuckMs = _opPos(n, "orchTaskStuckMs");
|
|
535
|
+
}
|
|
536
|
+
export function getOrchTaskStuckMsV2() {
|
|
537
|
+
return _otStuckMs;
|
|
538
|
+
}
|
|
481
539
|
|
|
482
540
|
export function _resetStateOrchestratorV2() {
|
|
483
|
-
_opsV2.clear();
|
|
484
|
-
|
|
485
|
-
|
|
541
|
+
_opsV2.clear();
|
|
542
|
+
_otsV2.clear();
|
|
543
|
+
_opMaxActivePerOwner = 6;
|
|
544
|
+
_opMaxPendingTasksPerProfile = 12;
|
|
545
|
+
_opIdleMs = 14 * 24 * 60 * 60 * 1000;
|
|
546
|
+
_otStuckMs = 15 * 60 * 1000;
|
|
486
547
|
}
|
|
487
548
|
|
|
488
549
|
export function registerOrchProfileV2({ id, owner, source, metadata } = {}) {
|
|
@@ -490,54 +551,238 @@ export function registerOrchProfileV2({ id, owner, source, metadata } = {}) {
|
|
|
490
551
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
491
552
|
if (_opsV2.has(id)) throw new Error(`orch profile ${id} already registered`);
|
|
492
553
|
const now = Date.now();
|
|
493
|
-
const p = {
|
|
554
|
+
const p = {
|
|
555
|
+
id,
|
|
556
|
+
owner,
|
|
557
|
+
source: source || "cli",
|
|
558
|
+
status: ORCH_PROFILE_MATURITY_V2.PENDING,
|
|
559
|
+
createdAt: now,
|
|
560
|
+
updatedAt: now,
|
|
561
|
+
activatedAt: null,
|
|
562
|
+
retiredAt: null,
|
|
563
|
+
lastTouchedAt: now,
|
|
564
|
+
metadata: { ...(metadata || {}) },
|
|
565
|
+
};
|
|
494
566
|
_opsV2.set(id, p);
|
|
495
567
|
return { ...p, metadata: { ...p.metadata } };
|
|
496
568
|
}
|
|
497
|
-
function _opCheckP(from, to) {
|
|
498
|
-
|
|
569
|
+
function _opCheckP(from, to) {
|
|
570
|
+
const a = _opTrans.get(from);
|
|
571
|
+
if (!a || !a.has(to))
|
|
572
|
+
throw new Error(`invalid orch profile transition ${from} → ${to}`);
|
|
573
|
+
}
|
|
574
|
+
function _opCountActive(owner) {
|
|
575
|
+
let n = 0;
|
|
576
|
+
for (const p of _opsV2.values())
|
|
577
|
+
if (p.owner === owner && p.status === ORCH_PROFILE_MATURITY_V2.ACTIVE) n++;
|
|
578
|
+
return n;
|
|
579
|
+
}
|
|
499
580
|
|
|
500
581
|
export function activateOrchProfileV2(id) {
|
|
501
|
-
const p = _opsV2.get(id);
|
|
582
|
+
const p = _opsV2.get(id);
|
|
583
|
+
if (!p) throw new Error(`orch profile ${id} not found`);
|
|
502
584
|
_opCheckP(p.status, ORCH_PROFILE_MATURITY_V2.ACTIVE);
|
|
503
585
|
const recovery = p.status === ORCH_PROFILE_MATURITY_V2.PAUSED;
|
|
504
|
-
if (!recovery) {
|
|
505
|
-
|
|
586
|
+
if (!recovery) {
|
|
587
|
+
const c = _opCountActive(p.owner);
|
|
588
|
+
if (c >= _opMaxActivePerOwner)
|
|
589
|
+
throw new Error(
|
|
590
|
+
`max active orch profiles per owner (${_opMaxActivePerOwner}) reached for ${p.owner}`,
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
const now = Date.now();
|
|
594
|
+
p.status = ORCH_PROFILE_MATURITY_V2.ACTIVE;
|
|
595
|
+
p.updatedAt = now;
|
|
596
|
+
p.lastTouchedAt = now;
|
|
597
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
598
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
599
|
+
}
|
|
600
|
+
export function pauseOrchProfileV2(id) {
|
|
601
|
+
const p = _opsV2.get(id);
|
|
602
|
+
if (!p) throw new Error(`orch profile ${id} not found`);
|
|
603
|
+
_opCheckP(p.status, ORCH_PROFILE_MATURITY_V2.PAUSED);
|
|
604
|
+
p.status = ORCH_PROFILE_MATURITY_V2.PAUSED;
|
|
605
|
+
p.updatedAt = Date.now();
|
|
606
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
607
|
+
}
|
|
608
|
+
export function retireOrchProfileV2(id) {
|
|
609
|
+
const p = _opsV2.get(id);
|
|
610
|
+
if (!p) throw new Error(`orch profile ${id} not found`);
|
|
611
|
+
_opCheckP(p.status, ORCH_PROFILE_MATURITY_V2.RETIRED);
|
|
612
|
+
const now = Date.now();
|
|
613
|
+
p.status = ORCH_PROFILE_MATURITY_V2.RETIRED;
|
|
614
|
+
p.updatedAt = now;
|
|
615
|
+
if (!p.retiredAt) p.retiredAt = now;
|
|
616
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
617
|
+
}
|
|
618
|
+
export function touchOrchProfileV2(id) {
|
|
619
|
+
const p = _opsV2.get(id);
|
|
620
|
+
if (!p) throw new Error(`orch profile ${id} not found`);
|
|
621
|
+
if (_opTerminal.has(p.status))
|
|
622
|
+
throw new Error(`cannot touch terminal orch profile ${id}`);
|
|
623
|
+
const now = Date.now();
|
|
624
|
+
p.lastTouchedAt = now;
|
|
625
|
+
p.updatedAt = now;
|
|
506
626
|
return { ...p, metadata: { ...p.metadata } };
|
|
507
627
|
}
|
|
508
|
-
export function
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
628
|
+
export function getOrchProfileV2(id) {
|
|
629
|
+
const p = _opsV2.get(id);
|
|
630
|
+
if (!p) return null;
|
|
631
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
632
|
+
}
|
|
633
|
+
export function listOrchProfilesV2() {
|
|
634
|
+
return [..._opsV2.values()].map((p) => ({
|
|
635
|
+
...p,
|
|
636
|
+
metadata: { ...p.metadata },
|
|
637
|
+
}));
|
|
638
|
+
}
|
|
513
639
|
|
|
514
|
-
function _otCountPending(profileId) {
|
|
640
|
+
function _otCountPending(profileId) {
|
|
641
|
+
let n = 0;
|
|
642
|
+
for (const t of _otsV2.values())
|
|
643
|
+
if (
|
|
644
|
+
t.profileId === profileId &&
|
|
645
|
+
(t.status === ORCH_TASK_LIFECYCLE_V2.QUEUED ||
|
|
646
|
+
t.status === ORCH_TASK_LIFECYCLE_V2.DISPATCHING)
|
|
647
|
+
)
|
|
648
|
+
n++;
|
|
649
|
+
return n;
|
|
650
|
+
}
|
|
515
651
|
|
|
516
652
|
export function createOrchTaskV2({ id, profileId, prompt, metadata } = {}) {
|
|
517
653
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
518
|
-
if (!profileId || typeof profileId !== "string")
|
|
654
|
+
if (!profileId || typeof profileId !== "string")
|
|
655
|
+
throw new Error("profileId is required");
|
|
519
656
|
if (_otsV2.has(id)) throw new Error(`orch task ${id} already exists`);
|
|
520
|
-
if (!_opsV2.has(profileId))
|
|
657
|
+
if (!_opsV2.has(profileId))
|
|
658
|
+
throw new Error(`orch profile ${profileId} not found`);
|
|
521
659
|
const pending = _otCountPending(profileId);
|
|
522
|
-
if (pending >= _opMaxPendingTasksPerProfile)
|
|
660
|
+
if (pending >= _opMaxPendingTasksPerProfile)
|
|
661
|
+
throw new Error(
|
|
662
|
+
`max pending orch tasks per profile (${_opMaxPendingTasksPerProfile}) reached for ${profileId}`,
|
|
663
|
+
);
|
|
523
664
|
const now = Date.now();
|
|
524
|
-
const t = {
|
|
665
|
+
const t = {
|
|
666
|
+
id,
|
|
667
|
+
profileId,
|
|
668
|
+
prompt: prompt || "",
|
|
669
|
+
status: ORCH_TASK_LIFECYCLE_V2.QUEUED,
|
|
670
|
+
createdAt: now,
|
|
671
|
+
updatedAt: now,
|
|
672
|
+
startedAt: null,
|
|
673
|
+
settledAt: null,
|
|
674
|
+
metadata: { ...(metadata || {}) },
|
|
675
|
+
};
|
|
525
676
|
_otsV2.set(id, t);
|
|
526
677
|
return { ...t, metadata: { ...t.metadata } };
|
|
527
678
|
}
|
|
528
|
-
function _otCheckT(from, to) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
export function
|
|
534
|
-
|
|
679
|
+
function _otCheckT(from, to) {
|
|
680
|
+
const a = _otTrans.get(from);
|
|
681
|
+
if (!a || !a.has(to))
|
|
682
|
+
throw new Error(`invalid orch task transition ${from} → ${to}`);
|
|
683
|
+
}
|
|
684
|
+
export function dispatchOrchTaskV2(id) {
|
|
685
|
+
const t = _otsV2.get(id);
|
|
686
|
+
if (!t) throw new Error(`orch task ${id} not found`);
|
|
687
|
+
_otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.DISPATCHING);
|
|
688
|
+
const now = Date.now();
|
|
689
|
+
t.status = ORCH_TASK_LIFECYCLE_V2.DISPATCHING;
|
|
690
|
+
t.updatedAt = now;
|
|
691
|
+
if (!t.startedAt) t.startedAt = now;
|
|
692
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
693
|
+
}
|
|
694
|
+
export function completeOrchTaskV2(id) {
|
|
695
|
+
const t = _otsV2.get(id);
|
|
696
|
+
if (!t) throw new Error(`orch task ${id} not found`);
|
|
697
|
+
_otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.COMPLETED);
|
|
698
|
+
const now = Date.now();
|
|
699
|
+
t.status = ORCH_TASK_LIFECYCLE_V2.COMPLETED;
|
|
700
|
+
t.updatedAt = now;
|
|
701
|
+
if (!t.settledAt) t.settledAt = now;
|
|
702
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
703
|
+
}
|
|
704
|
+
export function failOrchTaskV2(id, reason) {
|
|
705
|
+
const t = _otsV2.get(id);
|
|
706
|
+
if (!t) throw new Error(`orch task ${id} not found`);
|
|
707
|
+
_otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.FAILED);
|
|
708
|
+
const now = Date.now();
|
|
709
|
+
t.status = ORCH_TASK_LIFECYCLE_V2.FAILED;
|
|
710
|
+
t.updatedAt = now;
|
|
711
|
+
if (!t.settledAt) t.settledAt = now;
|
|
712
|
+
if (reason) t.metadata.failReason = String(reason);
|
|
713
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
714
|
+
}
|
|
715
|
+
export function cancelOrchTaskV2(id, reason) {
|
|
716
|
+
const t = _otsV2.get(id);
|
|
717
|
+
if (!t) throw new Error(`orch task ${id} not found`);
|
|
718
|
+
_otCheckT(t.status, ORCH_TASK_LIFECYCLE_V2.CANCELLED);
|
|
719
|
+
const now = Date.now();
|
|
720
|
+
t.status = ORCH_TASK_LIFECYCLE_V2.CANCELLED;
|
|
721
|
+
t.updatedAt = now;
|
|
722
|
+
if (!t.settledAt) t.settledAt = now;
|
|
723
|
+
if (reason) t.metadata.cancelReason = String(reason);
|
|
724
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
725
|
+
}
|
|
726
|
+
export function getOrchTaskV2(id) {
|
|
727
|
+
const t = _otsV2.get(id);
|
|
728
|
+
if (!t) return null;
|
|
729
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
730
|
+
}
|
|
731
|
+
export function listOrchTasksV2() {
|
|
732
|
+
return [..._otsV2.values()].map((t) => ({
|
|
733
|
+
...t,
|
|
734
|
+
metadata: { ...t.metadata },
|
|
735
|
+
}));
|
|
736
|
+
}
|
|
535
737
|
|
|
536
|
-
export function autoPauseIdleOrchProfilesV2({ now } = {}) {
|
|
537
|
-
|
|
738
|
+
export function autoPauseIdleOrchProfilesV2({ now } = {}) {
|
|
739
|
+
const t = now ?? Date.now();
|
|
740
|
+
const flipped = [];
|
|
741
|
+
for (const p of _opsV2.values())
|
|
742
|
+
if (
|
|
743
|
+
p.status === ORCH_PROFILE_MATURITY_V2.ACTIVE &&
|
|
744
|
+
t - p.lastTouchedAt >= _opIdleMs
|
|
745
|
+
) {
|
|
746
|
+
p.status = ORCH_PROFILE_MATURITY_V2.PAUSED;
|
|
747
|
+
p.updatedAt = t;
|
|
748
|
+
flipped.push(p.id);
|
|
749
|
+
}
|
|
750
|
+
return { flipped, count: flipped.length };
|
|
751
|
+
}
|
|
752
|
+
export function autoFailStuckOrchTasksV2({ now } = {}) {
|
|
753
|
+
const t = now ?? Date.now();
|
|
754
|
+
const flipped = [];
|
|
755
|
+
for (const x of _otsV2.values())
|
|
756
|
+
if (
|
|
757
|
+
x.status === ORCH_TASK_LIFECYCLE_V2.DISPATCHING &&
|
|
758
|
+
x.startedAt != null &&
|
|
759
|
+
t - x.startedAt >= _otStuckMs
|
|
760
|
+
) {
|
|
761
|
+
x.status = ORCH_TASK_LIFECYCLE_V2.FAILED;
|
|
762
|
+
x.updatedAt = t;
|
|
763
|
+
if (!x.settledAt) x.settledAt = t;
|
|
764
|
+
x.metadata.failReason = "auto-fail-stuck";
|
|
765
|
+
flipped.push(x.id);
|
|
766
|
+
}
|
|
767
|
+
return { flipped, count: flipped.length };
|
|
768
|
+
}
|
|
538
769
|
|
|
539
770
|
export function getOrchestratorGovStatsV2() {
|
|
540
|
-
const profilesByStatus = {};
|
|
541
|
-
|
|
542
|
-
|
|
771
|
+
const profilesByStatus = {};
|
|
772
|
+
for (const s of Object.values(ORCH_PROFILE_MATURITY_V2))
|
|
773
|
+
profilesByStatus[s] = 0;
|
|
774
|
+
for (const p of _opsV2.values()) profilesByStatus[p.status]++;
|
|
775
|
+
const tasksByStatus = {};
|
|
776
|
+
for (const s of Object.values(ORCH_TASK_LIFECYCLE_V2)) tasksByStatus[s] = 0;
|
|
777
|
+
for (const t of _otsV2.values()) tasksByStatus[t.status]++;
|
|
778
|
+
return {
|
|
779
|
+
totalOrchProfilesV2: _opsV2.size,
|
|
780
|
+
totalOrchTasksV2: _otsV2.size,
|
|
781
|
+
maxActiveOrchProfilesPerOwner: _opMaxActivePerOwner,
|
|
782
|
+
maxPendingOrchTasksPerProfile: _opMaxPendingTasksPerProfile,
|
|
783
|
+
orchProfileIdleMs: _opIdleMs,
|
|
784
|
+
orchTaskStuckMs: _otStuckMs,
|
|
785
|
+
profilesByStatus,
|
|
786
|
+
tasksByStatus,
|
|
787
|
+
};
|
|
543
788
|
}
|