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
|
@@ -245,81 +245,333 @@ export function getTaskTypes() {
|
|
|
245
245
|
|
|
246
246
|
// ===== V2 Surface: Task Model Selector governance overlay (CLI v0.141.0) =====
|
|
247
247
|
export const TMS_PROFILE_MATURITY_V2 = Object.freeze({
|
|
248
|
-
PENDING: "pending",
|
|
248
|
+
PENDING: "pending",
|
|
249
|
+
ACTIVE: "active",
|
|
250
|
+
STALE: "stale",
|
|
251
|
+
DECOMMISSIONED: "decommissioned",
|
|
249
252
|
});
|
|
250
253
|
export const TMS_SELECTION_LIFECYCLE_V2 = Object.freeze({
|
|
251
|
-
QUEUED: "queued",
|
|
254
|
+
QUEUED: "queued",
|
|
255
|
+
SCORING: "scoring",
|
|
256
|
+
COMPLETED: "completed",
|
|
257
|
+
FAILED: "failed",
|
|
258
|
+
CANCELLED: "cancelled",
|
|
252
259
|
});
|
|
253
260
|
const _tmsPTrans = new Map([
|
|
254
|
-
[
|
|
255
|
-
|
|
256
|
-
|
|
261
|
+
[
|
|
262
|
+
TMS_PROFILE_MATURITY_V2.PENDING,
|
|
263
|
+
new Set([
|
|
264
|
+
TMS_PROFILE_MATURITY_V2.ACTIVE,
|
|
265
|
+
TMS_PROFILE_MATURITY_V2.DECOMMISSIONED,
|
|
266
|
+
]),
|
|
267
|
+
],
|
|
268
|
+
[
|
|
269
|
+
TMS_PROFILE_MATURITY_V2.ACTIVE,
|
|
270
|
+
new Set([
|
|
271
|
+
TMS_PROFILE_MATURITY_V2.STALE,
|
|
272
|
+
TMS_PROFILE_MATURITY_V2.DECOMMISSIONED,
|
|
273
|
+
]),
|
|
274
|
+
],
|
|
275
|
+
[
|
|
276
|
+
TMS_PROFILE_MATURITY_V2.STALE,
|
|
277
|
+
new Set([
|
|
278
|
+
TMS_PROFILE_MATURITY_V2.ACTIVE,
|
|
279
|
+
TMS_PROFILE_MATURITY_V2.DECOMMISSIONED,
|
|
280
|
+
]),
|
|
281
|
+
],
|
|
257
282
|
[TMS_PROFILE_MATURITY_V2.DECOMMISSIONED, new Set()],
|
|
258
283
|
]);
|
|
259
284
|
const _tmsPTerminal = new Set([TMS_PROFILE_MATURITY_V2.DECOMMISSIONED]);
|
|
260
285
|
const _tmsSTrans = new Map([
|
|
261
|
-
[
|
|
262
|
-
|
|
286
|
+
[
|
|
287
|
+
TMS_SELECTION_LIFECYCLE_V2.QUEUED,
|
|
288
|
+
new Set([
|
|
289
|
+
TMS_SELECTION_LIFECYCLE_V2.SCORING,
|
|
290
|
+
TMS_SELECTION_LIFECYCLE_V2.CANCELLED,
|
|
291
|
+
]),
|
|
292
|
+
],
|
|
293
|
+
[
|
|
294
|
+
TMS_SELECTION_LIFECYCLE_V2.SCORING,
|
|
295
|
+
new Set([
|
|
296
|
+
TMS_SELECTION_LIFECYCLE_V2.COMPLETED,
|
|
297
|
+
TMS_SELECTION_LIFECYCLE_V2.FAILED,
|
|
298
|
+
TMS_SELECTION_LIFECYCLE_V2.CANCELLED,
|
|
299
|
+
]),
|
|
300
|
+
],
|
|
263
301
|
[TMS_SELECTION_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
264
302
|
[TMS_SELECTION_LIFECYCLE_V2.FAILED, new Set()],
|
|
265
303
|
[TMS_SELECTION_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
266
304
|
]);
|
|
267
305
|
const _tmsPsV2 = new Map();
|
|
268
306
|
const _tmsSsV2 = new Map();
|
|
269
|
-
let _tmsMaxActivePerOwner = 8,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
307
|
+
let _tmsMaxActivePerOwner = 8,
|
|
308
|
+
_tmsMaxPendingSelPerProfile = 16,
|
|
309
|
+
_tmsIdleMs = 14 * 24 * 60 * 60 * 1000,
|
|
310
|
+
_tmsStuckMs = 2 * 60 * 1000;
|
|
311
|
+
function _tmsPos(n, label) {
|
|
312
|
+
const v = Math.floor(Number(n));
|
|
313
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
314
|
+
throw new Error(`${label} must be positive integer`);
|
|
315
|
+
return v;
|
|
316
|
+
}
|
|
317
|
+
function _tmsCheckP(from, to) {
|
|
318
|
+
const a = _tmsPTrans.get(from);
|
|
319
|
+
if (!a || !a.has(to))
|
|
320
|
+
throw new Error(`invalid tms profile transition ${from} → ${to}`);
|
|
321
|
+
}
|
|
322
|
+
function _tmsCheckS(from, to) {
|
|
323
|
+
const a = _tmsSTrans.get(from);
|
|
324
|
+
if (!a || !a.has(to))
|
|
325
|
+
throw new Error(`invalid tms selection transition ${from} → ${to}`);
|
|
326
|
+
}
|
|
327
|
+
export function setMaxActiveTmsProfilesPerOwnerV2(n) {
|
|
328
|
+
_tmsMaxActivePerOwner = _tmsPos(n, "maxActiveTmsProfilesPerOwner");
|
|
329
|
+
}
|
|
330
|
+
export function getMaxActiveTmsProfilesPerOwnerV2() {
|
|
331
|
+
return _tmsMaxActivePerOwner;
|
|
332
|
+
}
|
|
333
|
+
export function setMaxPendingTmsSelectionsPerProfileV2(n) {
|
|
334
|
+
_tmsMaxPendingSelPerProfile = _tmsPos(n, "maxPendingTmsSelectionsPerProfile");
|
|
335
|
+
}
|
|
336
|
+
export function getMaxPendingTmsSelectionsPerProfileV2() {
|
|
337
|
+
return _tmsMaxPendingSelPerProfile;
|
|
338
|
+
}
|
|
339
|
+
export function setTmsProfileIdleMsV2(n) {
|
|
340
|
+
_tmsIdleMs = _tmsPos(n, "tmsProfileIdleMs");
|
|
341
|
+
}
|
|
342
|
+
export function getTmsProfileIdleMsV2() {
|
|
343
|
+
return _tmsIdleMs;
|
|
344
|
+
}
|
|
345
|
+
export function setTmsSelectionStuckMsV2(n) {
|
|
346
|
+
_tmsStuckMs = _tmsPos(n, "tmsSelectionStuckMs");
|
|
347
|
+
}
|
|
348
|
+
export function getTmsSelectionStuckMsV2() {
|
|
349
|
+
return _tmsStuckMs;
|
|
350
|
+
}
|
|
351
|
+
export function _resetStateTaskModelSelectorV2() {
|
|
352
|
+
_tmsPsV2.clear();
|
|
353
|
+
_tmsSsV2.clear();
|
|
354
|
+
_tmsMaxActivePerOwner = 8;
|
|
355
|
+
_tmsMaxPendingSelPerProfile = 16;
|
|
356
|
+
_tmsIdleMs = 14 * 24 * 60 * 60 * 1000;
|
|
357
|
+
_tmsStuckMs = 2 * 60 * 1000;
|
|
358
|
+
}
|
|
282
359
|
export function registerTmsProfileV2({ id, owner, strategy, metadata } = {}) {
|
|
283
|
-
if (!id) throw new Error("tms profile id required");
|
|
360
|
+
if (!id) throw new Error("tms profile id required");
|
|
361
|
+
if (!owner) throw new Error("tms profile owner required");
|
|
284
362
|
if (_tmsPsV2.has(id)) throw new Error(`tms profile ${id} already registered`);
|
|
285
363
|
const now = Date.now();
|
|
286
|
-
const p = {
|
|
287
|
-
|
|
364
|
+
const p = {
|
|
365
|
+
id,
|
|
366
|
+
owner,
|
|
367
|
+
strategy: strategy || "default",
|
|
368
|
+
status: TMS_PROFILE_MATURITY_V2.PENDING,
|
|
369
|
+
createdAt: now,
|
|
370
|
+
updatedAt: now,
|
|
371
|
+
activatedAt: null,
|
|
372
|
+
decommissionedAt: null,
|
|
373
|
+
lastTouchedAt: now,
|
|
374
|
+
metadata: { ...(metadata || {}) },
|
|
375
|
+
};
|
|
376
|
+
_tmsPsV2.set(id, p);
|
|
377
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
378
|
+
}
|
|
379
|
+
function _tmsCountActive(owner) {
|
|
380
|
+
let n = 0;
|
|
381
|
+
for (const p of _tmsPsV2.values())
|
|
382
|
+
if (p.owner === owner && p.status === TMS_PROFILE_MATURITY_V2.ACTIVE) n++;
|
|
383
|
+
return n;
|
|
288
384
|
}
|
|
289
|
-
function _tmsCountActive(owner) { let n = 0; for (const p of _tmsPsV2.values()) if (p.owner === owner && p.status === TMS_PROFILE_MATURITY_V2.ACTIVE) n++; return n; }
|
|
290
385
|
export function activateTmsProfileV2(id) {
|
|
291
|
-
const p = _tmsPsV2.get(id);
|
|
386
|
+
const p = _tmsPsV2.get(id);
|
|
387
|
+
if (!p) throw new Error(`tms profile ${id} not found`);
|
|
292
388
|
_tmsCheckP(p.status, TMS_PROFILE_MATURITY_V2.ACTIVE);
|
|
293
389
|
const recovery = p.status === TMS_PROFILE_MATURITY_V2.STALE;
|
|
294
|
-
if (!recovery && _tmsCountActive(p.owner) >= _tmsMaxActivePerOwner)
|
|
295
|
-
|
|
390
|
+
if (!recovery && _tmsCountActive(p.owner) >= _tmsMaxActivePerOwner)
|
|
391
|
+
throw new Error(`max active tms profiles for owner ${p.owner} reached`);
|
|
392
|
+
const now = Date.now();
|
|
393
|
+
p.status = TMS_PROFILE_MATURITY_V2.ACTIVE;
|
|
394
|
+
p.updatedAt = now;
|
|
395
|
+
p.lastTouchedAt = now;
|
|
396
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
397
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
398
|
+
}
|
|
399
|
+
export function staleTmsProfileV2(id) {
|
|
400
|
+
const p = _tmsPsV2.get(id);
|
|
401
|
+
if (!p) throw new Error(`tms profile ${id} not found`);
|
|
402
|
+
_tmsCheckP(p.status, TMS_PROFILE_MATURITY_V2.STALE);
|
|
403
|
+
p.status = TMS_PROFILE_MATURITY_V2.STALE;
|
|
404
|
+
p.updatedAt = Date.now();
|
|
296
405
|
return { ...p, metadata: { ...p.metadata } };
|
|
297
406
|
}
|
|
298
|
-
export function
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
407
|
+
export function decommissionTmsProfileV2(id) {
|
|
408
|
+
const p = _tmsPsV2.get(id);
|
|
409
|
+
if (!p) throw new Error(`tms profile ${id} not found`);
|
|
410
|
+
_tmsCheckP(p.status, TMS_PROFILE_MATURITY_V2.DECOMMISSIONED);
|
|
411
|
+
const now = Date.now();
|
|
412
|
+
p.status = TMS_PROFILE_MATURITY_V2.DECOMMISSIONED;
|
|
413
|
+
p.updatedAt = now;
|
|
414
|
+
if (!p.decommissionedAt) p.decommissionedAt = now;
|
|
415
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
416
|
+
}
|
|
417
|
+
export function touchTmsProfileV2(id) {
|
|
418
|
+
const p = _tmsPsV2.get(id);
|
|
419
|
+
if (!p) throw new Error(`tms profile ${id} not found`);
|
|
420
|
+
if (_tmsPTerminal.has(p.status))
|
|
421
|
+
throw new Error(`cannot touch terminal tms profile ${id}`);
|
|
422
|
+
const now = Date.now();
|
|
423
|
+
p.lastTouchedAt = now;
|
|
424
|
+
p.updatedAt = now;
|
|
425
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
426
|
+
}
|
|
427
|
+
export function getTmsProfileV2(id) {
|
|
428
|
+
const p = _tmsPsV2.get(id);
|
|
429
|
+
if (!p) return null;
|
|
430
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
431
|
+
}
|
|
432
|
+
export function listTmsProfilesV2() {
|
|
433
|
+
return [..._tmsPsV2.values()].map((p) => ({
|
|
434
|
+
...p,
|
|
435
|
+
metadata: { ...p.metadata },
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
438
|
+
function _tmsCountPending(profileId) {
|
|
439
|
+
let n = 0;
|
|
440
|
+
for (const s of _tmsSsV2.values())
|
|
441
|
+
if (
|
|
442
|
+
s.profileId === profileId &&
|
|
443
|
+
(s.status === TMS_SELECTION_LIFECYCLE_V2.QUEUED ||
|
|
444
|
+
s.status === TMS_SELECTION_LIFECYCLE_V2.SCORING)
|
|
445
|
+
)
|
|
446
|
+
n++;
|
|
447
|
+
return n;
|
|
448
|
+
}
|
|
304
449
|
export function createTmsSelectionV2({ id, profileId, task, metadata } = {}) {
|
|
305
|
-
if (!id) throw new Error("tms selection id required");
|
|
450
|
+
if (!id) throw new Error("tms selection id required");
|
|
451
|
+
if (!profileId) throw new Error("tms selection profileId required");
|
|
306
452
|
if (_tmsSsV2.has(id)) throw new Error(`tms selection ${id} already exists`);
|
|
307
|
-
if (!_tmsPsV2.has(profileId))
|
|
308
|
-
|
|
453
|
+
if (!_tmsPsV2.has(profileId))
|
|
454
|
+
throw new Error(`tms profile ${profileId} not found`);
|
|
455
|
+
if (_tmsCountPending(profileId) >= _tmsMaxPendingSelPerProfile)
|
|
456
|
+
throw new Error(
|
|
457
|
+
`max pending tms selections for profile ${profileId} reached`,
|
|
458
|
+
);
|
|
459
|
+
const now = Date.now();
|
|
460
|
+
const s = {
|
|
461
|
+
id,
|
|
462
|
+
profileId,
|
|
463
|
+
task: task || "",
|
|
464
|
+
status: TMS_SELECTION_LIFECYCLE_V2.QUEUED,
|
|
465
|
+
createdAt: now,
|
|
466
|
+
updatedAt: now,
|
|
467
|
+
startedAt: null,
|
|
468
|
+
settledAt: null,
|
|
469
|
+
metadata: { ...(metadata || {}) },
|
|
470
|
+
};
|
|
471
|
+
_tmsSsV2.set(id, s);
|
|
472
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
473
|
+
}
|
|
474
|
+
export function scoreTmsSelectionV2(id) {
|
|
475
|
+
const s = _tmsSsV2.get(id);
|
|
476
|
+
if (!s) throw new Error(`tms selection ${id} not found`);
|
|
477
|
+
_tmsCheckS(s.status, TMS_SELECTION_LIFECYCLE_V2.SCORING);
|
|
478
|
+
const now = Date.now();
|
|
479
|
+
s.status = TMS_SELECTION_LIFECYCLE_V2.SCORING;
|
|
480
|
+
s.updatedAt = now;
|
|
481
|
+
if (!s.startedAt) s.startedAt = now;
|
|
482
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
483
|
+
}
|
|
484
|
+
export function completeTmsSelectionV2(id) {
|
|
485
|
+
const s = _tmsSsV2.get(id);
|
|
486
|
+
if (!s) throw new Error(`tms selection ${id} not found`);
|
|
487
|
+
_tmsCheckS(s.status, TMS_SELECTION_LIFECYCLE_V2.COMPLETED);
|
|
488
|
+
const now = Date.now();
|
|
489
|
+
s.status = TMS_SELECTION_LIFECYCLE_V2.COMPLETED;
|
|
490
|
+
s.updatedAt = now;
|
|
491
|
+
if (!s.settledAt) s.settledAt = now;
|
|
492
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
493
|
+
}
|
|
494
|
+
export function failTmsSelectionV2(id, reason) {
|
|
495
|
+
const s = _tmsSsV2.get(id);
|
|
496
|
+
if (!s) throw new Error(`tms selection ${id} not found`);
|
|
497
|
+
_tmsCheckS(s.status, TMS_SELECTION_LIFECYCLE_V2.FAILED);
|
|
309
498
|
const now = Date.now();
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
export function cancelTmsSelectionV2(id, reason) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
499
|
+
s.status = TMS_SELECTION_LIFECYCLE_V2.FAILED;
|
|
500
|
+
s.updatedAt = now;
|
|
501
|
+
if (!s.settledAt) s.settledAt = now;
|
|
502
|
+
if (reason) s.metadata.failReason = String(reason);
|
|
503
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
504
|
+
}
|
|
505
|
+
export function cancelTmsSelectionV2(id, reason) {
|
|
506
|
+
const s = _tmsSsV2.get(id);
|
|
507
|
+
if (!s) throw new Error(`tms selection ${id} not found`);
|
|
508
|
+
_tmsCheckS(s.status, TMS_SELECTION_LIFECYCLE_V2.CANCELLED);
|
|
509
|
+
const now = Date.now();
|
|
510
|
+
s.status = TMS_SELECTION_LIFECYCLE_V2.CANCELLED;
|
|
511
|
+
s.updatedAt = now;
|
|
512
|
+
if (!s.settledAt) s.settledAt = now;
|
|
513
|
+
if (reason) s.metadata.cancelReason = String(reason);
|
|
514
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
515
|
+
}
|
|
516
|
+
export function getTmsSelectionV2(id) {
|
|
517
|
+
const s = _tmsSsV2.get(id);
|
|
518
|
+
if (!s) return null;
|
|
519
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
520
|
+
}
|
|
521
|
+
export function listTmsSelectionsV2() {
|
|
522
|
+
return [..._tmsSsV2.values()].map((s) => ({
|
|
523
|
+
...s,
|
|
524
|
+
metadata: { ...s.metadata },
|
|
525
|
+
}));
|
|
526
|
+
}
|
|
527
|
+
export function autoStaleIdleTmsProfilesV2({ now } = {}) {
|
|
528
|
+
const t = now ?? Date.now();
|
|
529
|
+
const flipped = [];
|
|
530
|
+
for (const p of _tmsPsV2.values())
|
|
531
|
+
if (
|
|
532
|
+
p.status === TMS_PROFILE_MATURITY_V2.ACTIVE &&
|
|
533
|
+
t - p.lastTouchedAt >= _tmsIdleMs
|
|
534
|
+
) {
|
|
535
|
+
p.status = TMS_PROFILE_MATURITY_V2.STALE;
|
|
536
|
+
p.updatedAt = t;
|
|
537
|
+
flipped.push(p.id);
|
|
538
|
+
}
|
|
539
|
+
return { flipped, count: flipped.length };
|
|
540
|
+
}
|
|
541
|
+
export function autoFailStuckTmsSelectionsV2({ now } = {}) {
|
|
542
|
+
const t = now ?? Date.now();
|
|
543
|
+
const flipped = [];
|
|
544
|
+
for (const s of _tmsSsV2.values())
|
|
545
|
+
if (
|
|
546
|
+
s.status === TMS_SELECTION_LIFECYCLE_V2.SCORING &&
|
|
547
|
+
s.startedAt != null &&
|
|
548
|
+
t - s.startedAt >= _tmsStuckMs
|
|
549
|
+
) {
|
|
550
|
+
s.status = TMS_SELECTION_LIFECYCLE_V2.FAILED;
|
|
551
|
+
s.updatedAt = t;
|
|
552
|
+
if (!s.settledAt) s.settledAt = t;
|
|
553
|
+
s.metadata.failReason = "auto-fail-stuck";
|
|
554
|
+
flipped.push(s.id);
|
|
555
|
+
}
|
|
556
|
+
return { flipped, count: flipped.length };
|
|
557
|
+
}
|
|
321
558
|
export function getTaskModelSelectorGovStatsV2() {
|
|
322
|
-
const profilesByStatus = {};
|
|
323
|
-
|
|
324
|
-
|
|
559
|
+
const profilesByStatus = {};
|
|
560
|
+
for (const v of Object.values(TMS_PROFILE_MATURITY_V2))
|
|
561
|
+
profilesByStatus[v] = 0;
|
|
562
|
+
for (const p of _tmsPsV2.values()) profilesByStatus[p.status]++;
|
|
563
|
+
const selectionsByStatus = {};
|
|
564
|
+
for (const v of Object.values(TMS_SELECTION_LIFECYCLE_V2))
|
|
565
|
+
selectionsByStatus[v] = 0;
|
|
566
|
+
for (const s of _tmsSsV2.values()) selectionsByStatus[s.status]++;
|
|
567
|
+
return {
|
|
568
|
+
totalTmsProfilesV2: _tmsPsV2.size,
|
|
569
|
+
totalTmsSelectionsV2: _tmsSsV2.size,
|
|
570
|
+
maxActiveTmsProfilesPerOwner: _tmsMaxActivePerOwner,
|
|
571
|
+
maxPendingTmsSelectionsPerProfile: _tmsMaxPendingSelPerProfile,
|
|
572
|
+
tmsProfileIdleMs: _tmsIdleMs,
|
|
573
|
+
tmsSelectionStuckMs: _tmsStuckMs,
|
|
574
|
+
profilesByStatus,
|
|
575
|
+
selectionsByStatus,
|
|
576
|
+
};
|
|
325
577
|
}
|