chainlesschain 0.145.0 → 0.156.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/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- 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 +213 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -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-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- 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 +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- 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 +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- 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/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
|
@@ -323,3 +323,333 @@ export class WebSocketInteractionAdapter extends InteractionAdapter {
|
|
|
323
323
|
pending.resolve(payload);
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
|
+
|
|
327
|
+
// =====================================================================
|
|
328
|
+
// interaction-adapter V2 governance overlay (iter26)
|
|
329
|
+
// =====================================================================
|
|
330
|
+
export const IAGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
331
|
+
PENDING: "pending",
|
|
332
|
+
ACTIVE: "active",
|
|
333
|
+
IDLE: "idle",
|
|
334
|
+
ARCHIVED: "archived",
|
|
335
|
+
});
|
|
336
|
+
export const IAGOV_TURN_LIFECYCLE_V2 = Object.freeze({
|
|
337
|
+
QUEUED: "queued",
|
|
338
|
+
RESPONDING: "responding",
|
|
339
|
+
RESPONDED: "responded",
|
|
340
|
+
FAILED: "failed",
|
|
341
|
+
CANCELLED: "cancelled",
|
|
342
|
+
});
|
|
343
|
+
const _iagovPTrans = new Map([
|
|
344
|
+
[
|
|
345
|
+
IAGOV_PROFILE_MATURITY_V2.PENDING,
|
|
346
|
+
new Set([
|
|
347
|
+
IAGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
348
|
+
IAGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
349
|
+
]),
|
|
350
|
+
],
|
|
351
|
+
[
|
|
352
|
+
IAGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
353
|
+
new Set([
|
|
354
|
+
IAGOV_PROFILE_MATURITY_V2.IDLE,
|
|
355
|
+
IAGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
356
|
+
]),
|
|
357
|
+
],
|
|
358
|
+
[
|
|
359
|
+
IAGOV_PROFILE_MATURITY_V2.IDLE,
|
|
360
|
+
new Set([
|
|
361
|
+
IAGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
362
|
+
IAGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
363
|
+
]),
|
|
364
|
+
],
|
|
365
|
+
[IAGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
366
|
+
]);
|
|
367
|
+
const _iagovPTerminal = new Set([IAGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
368
|
+
const _iagovJTrans = new Map([
|
|
369
|
+
[
|
|
370
|
+
IAGOV_TURN_LIFECYCLE_V2.QUEUED,
|
|
371
|
+
new Set([
|
|
372
|
+
IAGOV_TURN_LIFECYCLE_V2.RESPONDING,
|
|
373
|
+
IAGOV_TURN_LIFECYCLE_V2.CANCELLED,
|
|
374
|
+
]),
|
|
375
|
+
],
|
|
376
|
+
[
|
|
377
|
+
IAGOV_TURN_LIFECYCLE_V2.RESPONDING,
|
|
378
|
+
new Set([
|
|
379
|
+
IAGOV_TURN_LIFECYCLE_V2.RESPONDED,
|
|
380
|
+
IAGOV_TURN_LIFECYCLE_V2.FAILED,
|
|
381
|
+
IAGOV_TURN_LIFECYCLE_V2.CANCELLED,
|
|
382
|
+
]),
|
|
383
|
+
],
|
|
384
|
+
[IAGOV_TURN_LIFECYCLE_V2.RESPONDED, new Set()],
|
|
385
|
+
[IAGOV_TURN_LIFECYCLE_V2.FAILED, new Set()],
|
|
386
|
+
[IAGOV_TURN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
387
|
+
]);
|
|
388
|
+
const _iagovPsV2 = new Map();
|
|
389
|
+
const _iagovJsV2 = new Map();
|
|
390
|
+
let _iagovMaxActive = 6,
|
|
391
|
+
_iagovMaxPending = 15,
|
|
392
|
+
_iagovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
393
|
+
_iagovStuckMs = 60 * 1000;
|
|
394
|
+
function _iagovPos(n, label) {
|
|
395
|
+
const v = Math.floor(Number(n));
|
|
396
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
397
|
+
throw new Error(`${label} must be positive integer`);
|
|
398
|
+
return v;
|
|
399
|
+
}
|
|
400
|
+
function _iagovCheckP(from, to) {
|
|
401
|
+
const a = _iagovPTrans.get(from);
|
|
402
|
+
if (!a || !a.has(to))
|
|
403
|
+
throw new Error(`invalid iagov profile transition ${from} → ${to}`);
|
|
404
|
+
}
|
|
405
|
+
function _iagovCheckJ(from, to) {
|
|
406
|
+
const a = _iagovJTrans.get(from);
|
|
407
|
+
if (!a || !a.has(to))
|
|
408
|
+
throw new Error(`invalid iagov turn transition ${from} → ${to}`);
|
|
409
|
+
}
|
|
410
|
+
function _iagovCountActive(owner) {
|
|
411
|
+
let c = 0;
|
|
412
|
+
for (const p of _iagovPsV2.values())
|
|
413
|
+
if (p.owner === owner && p.status === IAGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
414
|
+
return c;
|
|
415
|
+
}
|
|
416
|
+
function _iagovCountPending(profileId) {
|
|
417
|
+
let c = 0;
|
|
418
|
+
for (const j of _iagovJsV2.values())
|
|
419
|
+
if (
|
|
420
|
+
j.profileId === profileId &&
|
|
421
|
+
(j.status === IAGOV_TURN_LIFECYCLE_V2.QUEUED ||
|
|
422
|
+
j.status === IAGOV_TURN_LIFECYCLE_V2.RESPONDING)
|
|
423
|
+
)
|
|
424
|
+
c++;
|
|
425
|
+
return c;
|
|
426
|
+
}
|
|
427
|
+
export function setMaxActiveIagovProfilesPerOwnerV2(n) {
|
|
428
|
+
_iagovMaxActive = _iagovPos(n, "maxActiveIagovProfilesPerOwner");
|
|
429
|
+
}
|
|
430
|
+
export function getMaxActiveIagovProfilesPerOwnerV2() {
|
|
431
|
+
return _iagovMaxActive;
|
|
432
|
+
}
|
|
433
|
+
export function setMaxPendingIagovTurnsPerProfileV2(n) {
|
|
434
|
+
_iagovMaxPending = _iagovPos(n, "maxPendingIagovTurnsPerProfile");
|
|
435
|
+
}
|
|
436
|
+
export function getMaxPendingIagovTurnsPerProfileV2() {
|
|
437
|
+
return _iagovMaxPending;
|
|
438
|
+
}
|
|
439
|
+
export function setIagovProfileIdleMsV2(n) {
|
|
440
|
+
_iagovIdleMs = _iagovPos(n, "iagovProfileIdleMs");
|
|
441
|
+
}
|
|
442
|
+
export function getIagovProfileIdleMsV2() {
|
|
443
|
+
return _iagovIdleMs;
|
|
444
|
+
}
|
|
445
|
+
export function setIagovTurnStuckMsV2(n) {
|
|
446
|
+
_iagovStuckMs = _iagovPos(n, "iagovTurnStuckMs");
|
|
447
|
+
}
|
|
448
|
+
export function getIagovTurnStuckMsV2() {
|
|
449
|
+
return _iagovStuckMs;
|
|
450
|
+
}
|
|
451
|
+
export function _resetStateInteractionAdapterGovV2() {
|
|
452
|
+
_iagovPsV2.clear();
|
|
453
|
+
_iagovJsV2.clear();
|
|
454
|
+
_iagovMaxActive = 6;
|
|
455
|
+
_iagovMaxPending = 15;
|
|
456
|
+
_iagovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
457
|
+
_iagovStuckMs = 60 * 1000;
|
|
458
|
+
}
|
|
459
|
+
export function registerIagovProfileV2({ id, owner, adapter, metadata } = {}) {
|
|
460
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
461
|
+
if (_iagovPsV2.has(id)) throw new Error(`iagov profile ${id} already exists`);
|
|
462
|
+
const now = Date.now();
|
|
463
|
+
const p = {
|
|
464
|
+
id,
|
|
465
|
+
owner,
|
|
466
|
+
adapter: adapter || "cli",
|
|
467
|
+
status: IAGOV_PROFILE_MATURITY_V2.PENDING,
|
|
468
|
+
createdAt: now,
|
|
469
|
+
updatedAt: now,
|
|
470
|
+
lastTouchedAt: now,
|
|
471
|
+
activatedAt: null,
|
|
472
|
+
archivedAt: null,
|
|
473
|
+
metadata: { ...(metadata || {}) },
|
|
474
|
+
};
|
|
475
|
+
_iagovPsV2.set(id, p);
|
|
476
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
477
|
+
}
|
|
478
|
+
export function activateIagovProfileV2(id) {
|
|
479
|
+
const p = _iagovPsV2.get(id);
|
|
480
|
+
if (!p) throw new Error(`iagov profile ${id} not found`);
|
|
481
|
+
const isInitial = p.status === IAGOV_PROFILE_MATURITY_V2.PENDING;
|
|
482
|
+
_iagovCheckP(p.status, IAGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
483
|
+
if (isInitial && _iagovCountActive(p.owner) >= _iagovMaxActive)
|
|
484
|
+
throw new Error(`max active iagov profiles for owner ${p.owner} reached`);
|
|
485
|
+
const now = Date.now();
|
|
486
|
+
p.status = IAGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
487
|
+
p.updatedAt = now;
|
|
488
|
+
p.lastTouchedAt = now;
|
|
489
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
490
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
491
|
+
}
|
|
492
|
+
export function idleIagovProfileV2(id) {
|
|
493
|
+
const p = _iagovPsV2.get(id);
|
|
494
|
+
if (!p) throw new Error(`iagov profile ${id} not found`);
|
|
495
|
+
_iagovCheckP(p.status, IAGOV_PROFILE_MATURITY_V2.IDLE);
|
|
496
|
+
p.status = IAGOV_PROFILE_MATURITY_V2.IDLE;
|
|
497
|
+
p.updatedAt = Date.now();
|
|
498
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
499
|
+
}
|
|
500
|
+
export function archiveIagovProfileV2(id) {
|
|
501
|
+
const p = _iagovPsV2.get(id);
|
|
502
|
+
if (!p) throw new Error(`iagov profile ${id} not found`);
|
|
503
|
+
_iagovCheckP(p.status, IAGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
504
|
+
const now = Date.now();
|
|
505
|
+
p.status = IAGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
506
|
+
p.updatedAt = now;
|
|
507
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
508
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
509
|
+
}
|
|
510
|
+
export function touchIagovProfileV2(id) {
|
|
511
|
+
const p = _iagovPsV2.get(id);
|
|
512
|
+
if (!p) throw new Error(`iagov profile ${id} not found`);
|
|
513
|
+
if (_iagovPTerminal.has(p.status))
|
|
514
|
+
throw new Error(`cannot touch terminal iagov profile ${id}`);
|
|
515
|
+
const now = Date.now();
|
|
516
|
+
p.lastTouchedAt = now;
|
|
517
|
+
p.updatedAt = now;
|
|
518
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
519
|
+
}
|
|
520
|
+
export function getIagovProfileV2(id) {
|
|
521
|
+
const p = _iagovPsV2.get(id);
|
|
522
|
+
if (!p) return null;
|
|
523
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
524
|
+
}
|
|
525
|
+
export function listIagovProfilesV2() {
|
|
526
|
+
return [..._iagovPsV2.values()].map((p) => ({
|
|
527
|
+
...p,
|
|
528
|
+
metadata: { ...p.metadata },
|
|
529
|
+
}));
|
|
530
|
+
}
|
|
531
|
+
export function createIagovTurnV2({ id, profileId, input, metadata } = {}) {
|
|
532
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
533
|
+
if (_iagovJsV2.has(id)) throw new Error(`iagov turn ${id} already exists`);
|
|
534
|
+
if (!_iagovPsV2.has(profileId))
|
|
535
|
+
throw new Error(`iagov profile ${profileId} not found`);
|
|
536
|
+
if (_iagovCountPending(profileId) >= _iagovMaxPending)
|
|
537
|
+
throw new Error(`max pending iagov turns for profile ${profileId} reached`);
|
|
538
|
+
const now = Date.now();
|
|
539
|
+
const j = {
|
|
540
|
+
id,
|
|
541
|
+
profileId,
|
|
542
|
+
input: input || "",
|
|
543
|
+
status: IAGOV_TURN_LIFECYCLE_V2.QUEUED,
|
|
544
|
+
createdAt: now,
|
|
545
|
+
updatedAt: now,
|
|
546
|
+
startedAt: null,
|
|
547
|
+
settledAt: null,
|
|
548
|
+
metadata: { ...(metadata || {}) },
|
|
549
|
+
};
|
|
550
|
+
_iagovJsV2.set(id, j);
|
|
551
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
552
|
+
}
|
|
553
|
+
export function respondingIagovTurnV2(id) {
|
|
554
|
+
const j = _iagovJsV2.get(id);
|
|
555
|
+
if (!j) throw new Error(`iagov turn ${id} not found`);
|
|
556
|
+
_iagovCheckJ(j.status, IAGOV_TURN_LIFECYCLE_V2.RESPONDING);
|
|
557
|
+
const now = Date.now();
|
|
558
|
+
j.status = IAGOV_TURN_LIFECYCLE_V2.RESPONDING;
|
|
559
|
+
j.updatedAt = now;
|
|
560
|
+
if (!j.startedAt) j.startedAt = now;
|
|
561
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
562
|
+
}
|
|
563
|
+
export function completeTurnIagovV2(id) {
|
|
564
|
+
const j = _iagovJsV2.get(id);
|
|
565
|
+
if (!j) throw new Error(`iagov turn ${id} not found`);
|
|
566
|
+
_iagovCheckJ(j.status, IAGOV_TURN_LIFECYCLE_V2.RESPONDED);
|
|
567
|
+
const now = Date.now();
|
|
568
|
+
j.status = IAGOV_TURN_LIFECYCLE_V2.RESPONDED;
|
|
569
|
+
j.updatedAt = now;
|
|
570
|
+
if (!j.settledAt) j.settledAt = now;
|
|
571
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
572
|
+
}
|
|
573
|
+
export function failIagovTurnV2(id, reason) {
|
|
574
|
+
const j = _iagovJsV2.get(id);
|
|
575
|
+
if (!j) throw new Error(`iagov turn ${id} not found`);
|
|
576
|
+
_iagovCheckJ(j.status, IAGOV_TURN_LIFECYCLE_V2.FAILED);
|
|
577
|
+
const now = Date.now();
|
|
578
|
+
j.status = IAGOV_TURN_LIFECYCLE_V2.FAILED;
|
|
579
|
+
j.updatedAt = now;
|
|
580
|
+
if (!j.settledAt) j.settledAt = now;
|
|
581
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
582
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
583
|
+
}
|
|
584
|
+
export function cancelIagovTurnV2(id, reason) {
|
|
585
|
+
const j = _iagovJsV2.get(id);
|
|
586
|
+
if (!j) throw new Error(`iagov turn ${id} not found`);
|
|
587
|
+
_iagovCheckJ(j.status, IAGOV_TURN_LIFECYCLE_V2.CANCELLED);
|
|
588
|
+
const now = Date.now();
|
|
589
|
+
j.status = IAGOV_TURN_LIFECYCLE_V2.CANCELLED;
|
|
590
|
+
j.updatedAt = now;
|
|
591
|
+
if (!j.settledAt) j.settledAt = now;
|
|
592
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
593
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
594
|
+
}
|
|
595
|
+
export function getIagovTurnV2(id) {
|
|
596
|
+
const j = _iagovJsV2.get(id);
|
|
597
|
+
if (!j) return null;
|
|
598
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
599
|
+
}
|
|
600
|
+
export function listIagovTurnsV2() {
|
|
601
|
+
return [..._iagovJsV2.values()].map((j) => ({
|
|
602
|
+
...j,
|
|
603
|
+
metadata: { ...j.metadata },
|
|
604
|
+
}));
|
|
605
|
+
}
|
|
606
|
+
export function autoIdleIdleIagovProfilesV2({ now } = {}) {
|
|
607
|
+
const t = now ?? Date.now();
|
|
608
|
+
const flipped = [];
|
|
609
|
+
for (const p of _iagovPsV2.values())
|
|
610
|
+
if (
|
|
611
|
+
p.status === IAGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
612
|
+
t - p.lastTouchedAt >= _iagovIdleMs
|
|
613
|
+
) {
|
|
614
|
+
p.status = IAGOV_PROFILE_MATURITY_V2.IDLE;
|
|
615
|
+
p.updatedAt = t;
|
|
616
|
+
flipped.push(p.id);
|
|
617
|
+
}
|
|
618
|
+
return { flipped, count: flipped.length };
|
|
619
|
+
}
|
|
620
|
+
export function autoFailStuckIagovTurnsV2({ now } = {}) {
|
|
621
|
+
const t = now ?? Date.now();
|
|
622
|
+
const flipped = [];
|
|
623
|
+
for (const j of _iagovJsV2.values())
|
|
624
|
+
if (
|
|
625
|
+
j.status === IAGOV_TURN_LIFECYCLE_V2.RESPONDING &&
|
|
626
|
+
j.startedAt != null &&
|
|
627
|
+
t - j.startedAt >= _iagovStuckMs
|
|
628
|
+
) {
|
|
629
|
+
j.status = IAGOV_TURN_LIFECYCLE_V2.FAILED;
|
|
630
|
+
j.updatedAt = t;
|
|
631
|
+
if (!j.settledAt) j.settledAt = t;
|
|
632
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
633
|
+
flipped.push(j.id);
|
|
634
|
+
}
|
|
635
|
+
return { flipped, count: flipped.length };
|
|
636
|
+
}
|
|
637
|
+
export function getInteractionAdapterGovStatsV2() {
|
|
638
|
+
const profilesByStatus = {};
|
|
639
|
+
for (const v of Object.values(IAGOV_PROFILE_MATURITY_V2))
|
|
640
|
+
profilesByStatus[v] = 0;
|
|
641
|
+
for (const p of _iagovPsV2.values()) profilesByStatus[p.status]++;
|
|
642
|
+
const turnsByStatus = {};
|
|
643
|
+
for (const v of Object.values(IAGOV_TURN_LIFECYCLE_V2)) turnsByStatus[v] = 0;
|
|
644
|
+
for (const j of _iagovJsV2.values()) turnsByStatus[j.status]++;
|
|
645
|
+
return {
|
|
646
|
+
totalIagovProfilesV2: _iagovPsV2.size,
|
|
647
|
+
totalIagovTurnsV2: _iagovJsV2.size,
|
|
648
|
+
maxActiveIagovProfilesPerOwner: _iagovMaxActive,
|
|
649
|
+
maxPendingIagovTurnsPerProfile: _iagovMaxPending,
|
|
650
|
+
iagovProfileIdleMs: _iagovIdleMs,
|
|
651
|
+
iagovTurnStuckMs: _iagovStuckMs,
|
|
652
|
+
profilesByStatus,
|
|
653
|
+
turnsByStatus,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
@@ -522,3 +522,357 @@ Keep plans concise (3-8 steps). Use appropriate tools for each step.`;
|
|
|
522
522
|
return Array.from(words);
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
|
+
|
|
526
|
+
// =====================================================================
|
|
527
|
+
// interactive-planner V2 governance overlay (iter26)
|
|
528
|
+
// =====================================================================
|
|
529
|
+
export const PLANNERGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
530
|
+
PENDING: "pending",
|
|
531
|
+
ACTIVE: "active",
|
|
532
|
+
PAUSED: "paused",
|
|
533
|
+
ARCHIVED: "archived",
|
|
534
|
+
});
|
|
535
|
+
export const PLANNERGOV_PROMPT_LIFECYCLE_V2 = Object.freeze({
|
|
536
|
+
QUEUED: "queued",
|
|
537
|
+
ASKING: "asking",
|
|
538
|
+
ANSWERED: "answered",
|
|
539
|
+
FAILED: "failed",
|
|
540
|
+
CANCELLED: "cancelled",
|
|
541
|
+
});
|
|
542
|
+
const _plannergovPTrans = new Map([
|
|
543
|
+
[
|
|
544
|
+
PLANNERGOV_PROFILE_MATURITY_V2.PENDING,
|
|
545
|
+
new Set([
|
|
546
|
+
PLANNERGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
547
|
+
PLANNERGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
548
|
+
]),
|
|
549
|
+
],
|
|
550
|
+
[
|
|
551
|
+
PLANNERGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
552
|
+
new Set([
|
|
553
|
+
PLANNERGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
554
|
+
PLANNERGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
555
|
+
]),
|
|
556
|
+
],
|
|
557
|
+
[
|
|
558
|
+
PLANNERGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
559
|
+
new Set([
|
|
560
|
+
PLANNERGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
561
|
+
PLANNERGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
562
|
+
]),
|
|
563
|
+
],
|
|
564
|
+
[PLANNERGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
565
|
+
]);
|
|
566
|
+
const _plannergovPTerminal = new Set([PLANNERGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
567
|
+
const _plannergovJTrans = new Map([
|
|
568
|
+
[
|
|
569
|
+
PLANNERGOV_PROMPT_LIFECYCLE_V2.QUEUED,
|
|
570
|
+
new Set([
|
|
571
|
+
PLANNERGOV_PROMPT_LIFECYCLE_V2.ASKING,
|
|
572
|
+
PLANNERGOV_PROMPT_LIFECYCLE_V2.CANCELLED,
|
|
573
|
+
]),
|
|
574
|
+
],
|
|
575
|
+
[
|
|
576
|
+
PLANNERGOV_PROMPT_LIFECYCLE_V2.ASKING,
|
|
577
|
+
new Set([
|
|
578
|
+
PLANNERGOV_PROMPT_LIFECYCLE_V2.ANSWERED,
|
|
579
|
+
PLANNERGOV_PROMPT_LIFECYCLE_V2.FAILED,
|
|
580
|
+
PLANNERGOV_PROMPT_LIFECYCLE_V2.CANCELLED,
|
|
581
|
+
]),
|
|
582
|
+
],
|
|
583
|
+
[PLANNERGOV_PROMPT_LIFECYCLE_V2.ANSWERED, new Set()],
|
|
584
|
+
[PLANNERGOV_PROMPT_LIFECYCLE_V2.FAILED, new Set()],
|
|
585
|
+
[PLANNERGOV_PROMPT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
586
|
+
]);
|
|
587
|
+
const _plannergovPsV2 = new Map();
|
|
588
|
+
const _plannergovJsV2 = new Map();
|
|
589
|
+
let _plannergovMaxActive = 6,
|
|
590
|
+
_plannergovMaxPending = 15,
|
|
591
|
+
_plannergovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
592
|
+
_plannergovStuckMs = 60 * 1000;
|
|
593
|
+
function _plannergovPos(n, label) {
|
|
594
|
+
const v = Math.floor(Number(n));
|
|
595
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
596
|
+
throw new Error(`${label} must be positive integer`);
|
|
597
|
+
return v;
|
|
598
|
+
}
|
|
599
|
+
function _plannergovCheckP(from, to) {
|
|
600
|
+
const a = _plannergovPTrans.get(from);
|
|
601
|
+
if (!a || !a.has(to))
|
|
602
|
+
throw new Error(`invalid plannergov profile transition ${from} → ${to}`);
|
|
603
|
+
}
|
|
604
|
+
function _plannergovCheckJ(from, to) {
|
|
605
|
+
const a = _plannergovJTrans.get(from);
|
|
606
|
+
if (!a || !a.has(to))
|
|
607
|
+
throw new Error(`invalid plannergov prompt transition ${from} → ${to}`);
|
|
608
|
+
}
|
|
609
|
+
function _plannergovCountActive(owner) {
|
|
610
|
+
let c = 0;
|
|
611
|
+
for (const p of _plannergovPsV2.values())
|
|
612
|
+
if (p.owner === owner && p.status === PLANNERGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
613
|
+
c++;
|
|
614
|
+
return c;
|
|
615
|
+
}
|
|
616
|
+
function _plannergovCountPending(profileId) {
|
|
617
|
+
let c = 0;
|
|
618
|
+
for (const j of _plannergovJsV2.values())
|
|
619
|
+
if (
|
|
620
|
+
j.profileId === profileId &&
|
|
621
|
+
(j.status === PLANNERGOV_PROMPT_LIFECYCLE_V2.QUEUED ||
|
|
622
|
+
j.status === PLANNERGOV_PROMPT_LIFECYCLE_V2.ASKING)
|
|
623
|
+
)
|
|
624
|
+
c++;
|
|
625
|
+
return c;
|
|
626
|
+
}
|
|
627
|
+
export function setMaxActivePlannergovProfilesPerOwnerV2(n) {
|
|
628
|
+
_plannergovMaxActive = _plannergovPos(
|
|
629
|
+
n,
|
|
630
|
+
"maxActivePlannergovProfilesPerOwner",
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
export function getMaxActivePlannergovProfilesPerOwnerV2() {
|
|
634
|
+
return _plannergovMaxActive;
|
|
635
|
+
}
|
|
636
|
+
export function setMaxPendingPlannergovPromptsPerProfileV2(n) {
|
|
637
|
+
_plannergovMaxPending = _plannergovPos(
|
|
638
|
+
n,
|
|
639
|
+
"maxPendingPlannergovPromptsPerProfile",
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
export function getMaxPendingPlannergovPromptsPerProfileV2() {
|
|
643
|
+
return _plannergovMaxPending;
|
|
644
|
+
}
|
|
645
|
+
export function setPlannergovProfileIdleMsV2(n) {
|
|
646
|
+
_plannergovIdleMs = _plannergovPos(n, "plannergovProfileIdleMs");
|
|
647
|
+
}
|
|
648
|
+
export function getPlannergovProfileIdleMsV2() {
|
|
649
|
+
return _plannergovIdleMs;
|
|
650
|
+
}
|
|
651
|
+
export function setPlannergovPromptStuckMsV2(n) {
|
|
652
|
+
_plannergovStuckMs = _plannergovPos(n, "plannergovPromptStuckMs");
|
|
653
|
+
}
|
|
654
|
+
export function getPlannergovPromptStuckMsV2() {
|
|
655
|
+
return _plannergovStuckMs;
|
|
656
|
+
}
|
|
657
|
+
export function _resetStateInteractivePlannerGovV2() {
|
|
658
|
+
_plannergovPsV2.clear();
|
|
659
|
+
_plannergovJsV2.clear();
|
|
660
|
+
_plannergovMaxActive = 6;
|
|
661
|
+
_plannergovMaxPending = 15;
|
|
662
|
+
_plannergovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
663
|
+
_plannergovStuckMs = 60 * 1000;
|
|
664
|
+
}
|
|
665
|
+
export function registerPlannergovProfileV2({
|
|
666
|
+
id,
|
|
667
|
+
owner,
|
|
668
|
+
persona,
|
|
669
|
+
metadata,
|
|
670
|
+
} = {}) {
|
|
671
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
672
|
+
if (_plannergovPsV2.has(id))
|
|
673
|
+
throw new Error(`plannergov profile ${id} already exists`);
|
|
674
|
+
const now = Date.now();
|
|
675
|
+
const p = {
|
|
676
|
+
id,
|
|
677
|
+
owner,
|
|
678
|
+
persona: persona || "default",
|
|
679
|
+
status: PLANNERGOV_PROFILE_MATURITY_V2.PENDING,
|
|
680
|
+
createdAt: now,
|
|
681
|
+
updatedAt: now,
|
|
682
|
+
lastTouchedAt: now,
|
|
683
|
+
activatedAt: null,
|
|
684
|
+
archivedAt: null,
|
|
685
|
+
metadata: { ...(metadata || {}) },
|
|
686
|
+
};
|
|
687
|
+
_plannergovPsV2.set(id, p);
|
|
688
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
689
|
+
}
|
|
690
|
+
export function activatePlannergovProfileV2(id) {
|
|
691
|
+
const p = _plannergovPsV2.get(id);
|
|
692
|
+
if (!p) throw new Error(`plannergov profile ${id} not found`);
|
|
693
|
+
const isInitial = p.status === PLANNERGOV_PROFILE_MATURITY_V2.PENDING;
|
|
694
|
+
_plannergovCheckP(p.status, PLANNERGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
695
|
+
if (isInitial && _plannergovCountActive(p.owner) >= _plannergovMaxActive)
|
|
696
|
+
throw new Error(
|
|
697
|
+
`max active plannergov profiles for owner ${p.owner} reached`,
|
|
698
|
+
);
|
|
699
|
+
const now = Date.now();
|
|
700
|
+
p.status = PLANNERGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
701
|
+
p.updatedAt = now;
|
|
702
|
+
p.lastTouchedAt = now;
|
|
703
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
704
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
705
|
+
}
|
|
706
|
+
export function pausePlannergovProfileV2(id) {
|
|
707
|
+
const p = _plannergovPsV2.get(id);
|
|
708
|
+
if (!p) throw new Error(`plannergov profile ${id} not found`);
|
|
709
|
+
_plannergovCheckP(p.status, PLANNERGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
710
|
+
p.status = PLANNERGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
711
|
+
p.updatedAt = Date.now();
|
|
712
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
713
|
+
}
|
|
714
|
+
export function archivePlannergovProfileV2(id) {
|
|
715
|
+
const p = _plannergovPsV2.get(id);
|
|
716
|
+
if (!p) throw new Error(`plannergov profile ${id} not found`);
|
|
717
|
+
_plannergovCheckP(p.status, PLANNERGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
718
|
+
const now = Date.now();
|
|
719
|
+
p.status = PLANNERGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
720
|
+
p.updatedAt = now;
|
|
721
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
722
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
723
|
+
}
|
|
724
|
+
export function touchPlannergovProfileV2(id) {
|
|
725
|
+
const p = _plannergovPsV2.get(id);
|
|
726
|
+
if (!p) throw new Error(`plannergov profile ${id} not found`);
|
|
727
|
+
if (_plannergovPTerminal.has(p.status))
|
|
728
|
+
throw new Error(`cannot touch terminal plannergov profile ${id}`);
|
|
729
|
+
const now = Date.now();
|
|
730
|
+
p.lastTouchedAt = now;
|
|
731
|
+
p.updatedAt = now;
|
|
732
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
733
|
+
}
|
|
734
|
+
export function getPlannergovProfileV2(id) {
|
|
735
|
+
const p = _plannergovPsV2.get(id);
|
|
736
|
+
if (!p) return null;
|
|
737
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
738
|
+
}
|
|
739
|
+
export function listPlannergovProfilesV2() {
|
|
740
|
+
return [..._plannergovPsV2.values()].map((p) => ({
|
|
741
|
+
...p,
|
|
742
|
+
metadata: { ...p.metadata },
|
|
743
|
+
}));
|
|
744
|
+
}
|
|
745
|
+
export function createPlannergovPromptV2({
|
|
746
|
+
id,
|
|
747
|
+
profileId,
|
|
748
|
+
question,
|
|
749
|
+
metadata,
|
|
750
|
+
} = {}) {
|
|
751
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
752
|
+
if (_plannergovJsV2.has(id))
|
|
753
|
+
throw new Error(`plannergov prompt ${id} already exists`);
|
|
754
|
+
if (!_plannergovPsV2.has(profileId))
|
|
755
|
+
throw new Error(`plannergov profile ${profileId} not found`);
|
|
756
|
+
if (_plannergovCountPending(profileId) >= _plannergovMaxPending)
|
|
757
|
+
throw new Error(
|
|
758
|
+
`max pending plannergov prompts for profile ${profileId} reached`,
|
|
759
|
+
);
|
|
760
|
+
const now = Date.now();
|
|
761
|
+
const j = {
|
|
762
|
+
id,
|
|
763
|
+
profileId,
|
|
764
|
+
question: question || "",
|
|
765
|
+
status: PLANNERGOV_PROMPT_LIFECYCLE_V2.QUEUED,
|
|
766
|
+
createdAt: now,
|
|
767
|
+
updatedAt: now,
|
|
768
|
+
startedAt: null,
|
|
769
|
+
settledAt: null,
|
|
770
|
+
metadata: { ...(metadata || {}) },
|
|
771
|
+
};
|
|
772
|
+
_plannergovJsV2.set(id, j);
|
|
773
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
774
|
+
}
|
|
775
|
+
export function askingPlannergovPromptV2(id) {
|
|
776
|
+
const j = _plannergovJsV2.get(id);
|
|
777
|
+
if (!j) throw new Error(`plannergov prompt ${id} not found`);
|
|
778
|
+
_plannergovCheckJ(j.status, PLANNERGOV_PROMPT_LIFECYCLE_V2.ASKING);
|
|
779
|
+
const now = Date.now();
|
|
780
|
+
j.status = PLANNERGOV_PROMPT_LIFECYCLE_V2.ASKING;
|
|
781
|
+
j.updatedAt = now;
|
|
782
|
+
if (!j.startedAt) j.startedAt = now;
|
|
783
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
784
|
+
}
|
|
785
|
+
export function completePromptPlannergovV2(id) {
|
|
786
|
+
const j = _plannergovJsV2.get(id);
|
|
787
|
+
if (!j) throw new Error(`plannergov prompt ${id} not found`);
|
|
788
|
+
_plannergovCheckJ(j.status, PLANNERGOV_PROMPT_LIFECYCLE_V2.ANSWERED);
|
|
789
|
+
const now = Date.now();
|
|
790
|
+
j.status = PLANNERGOV_PROMPT_LIFECYCLE_V2.ANSWERED;
|
|
791
|
+
j.updatedAt = now;
|
|
792
|
+
if (!j.settledAt) j.settledAt = now;
|
|
793
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
794
|
+
}
|
|
795
|
+
export function failPlannergovPromptV2(id, reason) {
|
|
796
|
+
const j = _plannergovJsV2.get(id);
|
|
797
|
+
if (!j) throw new Error(`plannergov prompt ${id} not found`);
|
|
798
|
+
_plannergovCheckJ(j.status, PLANNERGOV_PROMPT_LIFECYCLE_V2.FAILED);
|
|
799
|
+
const now = Date.now();
|
|
800
|
+
j.status = PLANNERGOV_PROMPT_LIFECYCLE_V2.FAILED;
|
|
801
|
+
j.updatedAt = now;
|
|
802
|
+
if (!j.settledAt) j.settledAt = now;
|
|
803
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
804
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
805
|
+
}
|
|
806
|
+
export function cancelPlannergovPromptV2(id, reason) {
|
|
807
|
+
const j = _plannergovJsV2.get(id);
|
|
808
|
+
if (!j) throw new Error(`plannergov prompt ${id} not found`);
|
|
809
|
+
_plannergovCheckJ(j.status, PLANNERGOV_PROMPT_LIFECYCLE_V2.CANCELLED);
|
|
810
|
+
const now = Date.now();
|
|
811
|
+
j.status = PLANNERGOV_PROMPT_LIFECYCLE_V2.CANCELLED;
|
|
812
|
+
j.updatedAt = now;
|
|
813
|
+
if (!j.settledAt) j.settledAt = now;
|
|
814
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
815
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
816
|
+
}
|
|
817
|
+
export function getPlannergovPromptV2(id) {
|
|
818
|
+
const j = _plannergovJsV2.get(id);
|
|
819
|
+
if (!j) return null;
|
|
820
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
821
|
+
}
|
|
822
|
+
export function listPlannergovPromptsV2() {
|
|
823
|
+
return [..._plannergovJsV2.values()].map((j) => ({
|
|
824
|
+
...j,
|
|
825
|
+
metadata: { ...j.metadata },
|
|
826
|
+
}));
|
|
827
|
+
}
|
|
828
|
+
export function autoPauseIdlePlannergovProfilesV2({ now } = {}) {
|
|
829
|
+
const t = now ?? Date.now();
|
|
830
|
+
const flipped = [];
|
|
831
|
+
for (const p of _plannergovPsV2.values())
|
|
832
|
+
if (
|
|
833
|
+
p.status === PLANNERGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
834
|
+
t - p.lastTouchedAt >= _plannergovIdleMs
|
|
835
|
+
) {
|
|
836
|
+
p.status = PLANNERGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
837
|
+
p.updatedAt = t;
|
|
838
|
+
flipped.push(p.id);
|
|
839
|
+
}
|
|
840
|
+
return { flipped, count: flipped.length };
|
|
841
|
+
}
|
|
842
|
+
export function autoFailStuckPlannergovPromptsV2({ now } = {}) {
|
|
843
|
+
const t = now ?? Date.now();
|
|
844
|
+
const flipped = [];
|
|
845
|
+
for (const j of _plannergovJsV2.values())
|
|
846
|
+
if (
|
|
847
|
+
j.status === PLANNERGOV_PROMPT_LIFECYCLE_V2.ASKING &&
|
|
848
|
+
j.startedAt != null &&
|
|
849
|
+
t - j.startedAt >= _plannergovStuckMs
|
|
850
|
+
) {
|
|
851
|
+
j.status = PLANNERGOV_PROMPT_LIFECYCLE_V2.FAILED;
|
|
852
|
+
j.updatedAt = t;
|
|
853
|
+
if (!j.settledAt) j.settledAt = t;
|
|
854
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
855
|
+
flipped.push(j.id);
|
|
856
|
+
}
|
|
857
|
+
return { flipped, count: flipped.length };
|
|
858
|
+
}
|
|
859
|
+
export function getInteractivePlannerGovStatsV2() {
|
|
860
|
+
const profilesByStatus = {};
|
|
861
|
+
for (const v of Object.values(PLANNERGOV_PROFILE_MATURITY_V2))
|
|
862
|
+
profilesByStatus[v] = 0;
|
|
863
|
+
for (const p of _plannergovPsV2.values()) profilesByStatus[p.status]++;
|
|
864
|
+
const promptsByStatus = {};
|
|
865
|
+
for (const v of Object.values(PLANNERGOV_PROMPT_LIFECYCLE_V2))
|
|
866
|
+
promptsByStatus[v] = 0;
|
|
867
|
+
for (const j of _plannergovJsV2.values()) promptsByStatus[j.status]++;
|
|
868
|
+
return {
|
|
869
|
+
totalPlannergovProfilesV2: _plannergovPsV2.size,
|
|
870
|
+
totalPlannergovPromptsV2: _plannergovJsV2.size,
|
|
871
|
+
maxActivePlannergovProfilesPerOwner: _plannergovMaxActive,
|
|
872
|
+
maxPendingPlannergovPromptsPerProfile: _plannergovMaxPending,
|
|
873
|
+
plannergovProfileIdleMs: _plannergovIdleMs,
|
|
874
|
+
plannergovPromptStuckMs: _plannergovStuckMs,
|
|
875
|
+
profilesByStatus,
|
|
876
|
+
promptsByStatus,
|
|
877
|
+
};
|
|
878
|
+
}
|