chainlesschain 0.132.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 +230 -0
- package/src/commands/activitypub.js +191 -0
- package/src/commands/agent.js +601 -0
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +186 -0
- package/src/commands/bm25.js +162 -0
- package/src/commands/browse.js +225 -0
- package/src/commands/ccron.js +178 -0
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +420 -0
- package/src/commands/compt.js +176 -0
- package/src/commands/consol.js +237 -0
- package/src/commands/cowork.js +588 -0
- package/src/commands/crosschain.js +216 -0
- package/src/commands/dao.js +216 -0
- package/src/commands/dlp.js +206 -0
- package/src/commands/economy.js +211 -0
- package/src/commands/evolution.js +209 -0
- package/src/commands/evomap.js +216 -0
- package/src/commands/fflag.js +230 -0
- package/src/commands/git.js +185 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +210 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +178 -0
- package/src/commands/itbudget.js +161 -0
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +201 -0
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +214 -0
- package/src/commands/mcpscaf.js +153 -0
- package/src/commands/meminj.js +153 -0
- package/src/commands/nostr.js +213 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +156 -0
- package/src/commands/pdfp.js +160 -0
- package/src/commands/perf.js +176 -0
- package/src/commands/perm.js +156 -0
- package/src/commands/pipeline.js +211 -0
- package/src/commands/planmode.js +154 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +166 -0
- package/src/commands/recommend.js +185 -0
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/seshhook.js +153 -0
- package/src/commands/seshsearch.js +149 -0
- package/src/commands/seshtail.js +152 -0
- package/src/commands/seshu.js +160 -0
- package/src/commands/sganal.js +172 -0
- package/src/commands/siem.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +154 -0
- package/src/commands/social.js +159 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +157 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +183 -0
- package/src/commands/topiccls.js +158 -0
- package/src/commands/uprof.js +154 -0
- package/src/commands/vcheck.js +172 -0
- package/src/commands/webfetch.js +150 -0
- package/src/commands/zkp.js +218 -0
- package/src/harness/prompt-compressor.js +331 -0
- package/src/index.js +101 -1
- package/src/lib/a2a-protocol.js +373 -0
- package/src/lib/activitypub-bridge.js +343 -0
- package/src/lib/agent-economy.js +358 -0
- package/src/lib/app-builder.js +338 -0
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +341 -0
- package/src/lib/bi-engine.js +339 -0
- package/src/lib/bm25-search.js +333 -0
- package/src/lib/browser-automation.js +352 -0
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/compliance-framework-reporter.js +359 -0
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +333 -0
- package/src/lib/content-recommender.js +370 -0
- package/src/lib/cowork-cron.js +330 -0
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-task-runner.js +362 -0
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +365 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/dlp-engine.js +343 -0
- package/src/lib/evolution-system.js +336 -0
- package/src/lib/evomap-manager.js +339 -0
- package/src/lib/execution-backend.js +351 -0
- package/src/lib/feature-flags.js +330 -0
- package/src/lib/git-integration.js +343 -0
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +341 -0
- package/src/lib/inference-network.js +362 -0
- package/src/lib/iteration-budget.js +357 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-scaffold.js +345 -0
- package/src/lib/memory-injection.js +320 -0
- package/src/lib/nostr-bridge.js +342 -0
- package/src/lib/orchestrator.js +350 -0
- package/src/lib/pdf-parser.js +330 -0
- package/src/lib/perf-tuning.js +364 -0
- package/src/lib/permission-engine.js +319 -0
- package/src/lib/pipeline-orchestrator.js +345 -0
- package/src/lib/plan-mode.js +328 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/prompt-compressor.js +1 -10
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/service-container.js +342 -0
- package/src/lib/session-consolidator.js +352 -0
- package/src/lib/session-hooks.js +340 -0
- package/src/lib/session-search.js +334 -0
- package/src/lib/session-tail.js +320 -0
- package/src/lib/session-usage.js +329 -0
- package/src/lib/siem-exporter.js +352 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +333 -0
- package/src/lib/social-graph-analytics.js +327 -0
- package/src/lib/social-graph.js +304 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +359 -0
- package/src/lib/task-model-selector.js +333 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +339 -0
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +353 -0
- package/src/lib/user-profile.js +325 -0
- package/src/lib/version-checker.js +335 -0
- package/src/lib/web-fetch.js +322 -0
- package/src/lib/zkp-engine.js +342 -0
|
@@ -173,3 +173,360 @@ export class IterationBudget {
|
|
|
173
173
|
export const DEFAULT_ITERATION_BUDGET = DEFAULT_BUDGET;
|
|
174
174
|
export const BUDGET_WARNING_THRESHOLD = WARNING_THRESHOLD;
|
|
175
175
|
export const BUDGET_WRAPPING_UP_THRESHOLD = WRAPPING_UP_THRESHOLD;
|
|
176
|
+
|
|
177
|
+
// ===== V2 Surface: Iteration Budget governance overlay (CLI v0.140.0) =====
|
|
178
|
+
export const ITER_BUDGET_PROFILE_MATURITY_V2 = Object.freeze({
|
|
179
|
+
PENDING: "pending",
|
|
180
|
+
ACTIVE: "active",
|
|
181
|
+
PAUSED: "paused",
|
|
182
|
+
EXHAUSTED: "exhausted",
|
|
183
|
+
});
|
|
184
|
+
export const ITER_RUN_LIFECYCLE_V2 = Object.freeze({
|
|
185
|
+
QUEUED: "queued",
|
|
186
|
+
RUNNING: "running",
|
|
187
|
+
COMPLETED: "completed",
|
|
188
|
+
FAILED: "failed",
|
|
189
|
+
CANCELLED: "cancelled",
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const _ibpTrans = new Map([
|
|
193
|
+
[
|
|
194
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.PENDING,
|
|
195
|
+
new Set([
|
|
196
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
|
|
197
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
|
|
198
|
+
]),
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
|
|
202
|
+
new Set([
|
|
203
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED,
|
|
204
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
|
|
205
|
+
]),
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED,
|
|
209
|
+
new Set([
|
|
210
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE,
|
|
211
|
+
ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED,
|
|
212
|
+
]),
|
|
213
|
+
],
|
|
214
|
+
[ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED, new Set()],
|
|
215
|
+
]);
|
|
216
|
+
const _ibpTerminal = new Set([ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED]);
|
|
217
|
+
const _irTrans = new Map([
|
|
218
|
+
[
|
|
219
|
+
ITER_RUN_LIFECYCLE_V2.QUEUED,
|
|
220
|
+
new Set([ITER_RUN_LIFECYCLE_V2.RUNNING, ITER_RUN_LIFECYCLE_V2.CANCELLED]),
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
ITER_RUN_LIFECYCLE_V2.RUNNING,
|
|
224
|
+
new Set([
|
|
225
|
+
ITER_RUN_LIFECYCLE_V2.COMPLETED,
|
|
226
|
+
ITER_RUN_LIFECYCLE_V2.FAILED,
|
|
227
|
+
ITER_RUN_LIFECYCLE_V2.CANCELLED,
|
|
228
|
+
]),
|
|
229
|
+
],
|
|
230
|
+
[ITER_RUN_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
231
|
+
[ITER_RUN_LIFECYCLE_V2.FAILED, new Set()],
|
|
232
|
+
[ITER_RUN_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
233
|
+
]);
|
|
234
|
+
|
|
235
|
+
const _ibpsV2 = new Map();
|
|
236
|
+
const _irsV2 = new Map();
|
|
237
|
+
let _ibpMaxActivePerOwner = 4;
|
|
238
|
+
let _ibpMaxPendingRunsPerProfile = 8;
|
|
239
|
+
let _ibpIdleMs = 24 * 60 * 60 * 1000;
|
|
240
|
+
let _irStuckMs = 60 * 60 * 1000;
|
|
241
|
+
|
|
242
|
+
function _ibpPos(n, lbl) {
|
|
243
|
+
const v = Math.floor(Number(n));
|
|
244
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
245
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
246
|
+
return v;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function setMaxActiveIterBudgetProfilesPerOwnerV2(n) {
|
|
250
|
+
_ibpMaxActivePerOwner = _ibpPos(n, "maxActiveIterBudgetProfilesPerOwner");
|
|
251
|
+
}
|
|
252
|
+
export function getMaxActiveIterBudgetProfilesPerOwnerV2() {
|
|
253
|
+
return _ibpMaxActivePerOwner;
|
|
254
|
+
}
|
|
255
|
+
export function setMaxPendingIterRunsPerProfileV2(n) {
|
|
256
|
+
_ibpMaxPendingRunsPerProfile = _ibpPos(n, "maxPendingIterRunsPerProfile");
|
|
257
|
+
}
|
|
258
|
+
export function getMaxPendingIterRunsPerProfileV2() {
|
|
259
|
+
return _ibpMaxPendingRunsPerProfile;
|
|
260
|
+
}
|
|
261
|
+
export function setIterBudgetProfileIdleMsV2(n) {
|
|
262
|
+
_ibpIdleMs = _ibpPos(n, "iterBudgetProfileIdleMs");
|
|
263
|
+
}
|
|
264
|
+
export function getIterBudgetProfileIdleMsV2() {
|
|
265
|
+
return _ibpIdleMs;
|
|
266
|
+
}
|
|
267
|
+
export function setIterRunStuckMsV2(n) {
|
|
268
|
+
_irStuckMs = _ibpPos(n, "iterRunStuckMs");
|
|
269
|
+
}
|
|
270
|
+
export function getIterRunStuckMsV2() {
|
|
271
|
+
return _irStuckMs;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function _resetStateIterationBudgetV2() {
|
|
275
|
+
_ibpsV2.clear();
|
|
276
|
+
_irsV2.clear();
|
|
277
|
+
_ibpMaxActivePerOwner = 4;
|
|
278
|
+
_ibpMaxPendingRunsPerProfile = 8;
|
|
279
|
+
_ibpIdleMs = 24 * 60 * 60 * 1000;
|
|
280
|
+
_irStuckMs = 60 * 60 * 1000;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function registerIterBudgetProfileV2({
|
|
284
|
+
id,
|
|
285
|
+
owner,
|
|
286
|
+
budget,
|
|
287
|
+
metadata,
|
|
288
|
+
} = {}) {
|
|
289
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
290
|
+
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
291
|
+
if (_ibpsV2.has(id))
|
|
292
|
+
throw new Error(`iter budget profile ${id} already registered`);
|
|
293
|
+
const now = Date.now();
|
|
294
|
+
const p = {
|
|
295
|
+
id,
|
|
296
|
+
owner,
|
|
297
|
+
budget: budget || 50,
|
|
298
|
+
status: ITER_BUDGET_PROFILE_MATURITY_V2.PENDING,
|
|
299
|
+
createdAt: now,
|
|
300
|
+
updatedAt: now,
|
|
301
|
+
activatedAt: null,
|
|
302
|
+
exhaustedAt: null,
|
|
303
|
+
lastTouchedAt: now,
|
|
304
|
+
metadata: { ...(metadata || {}) },
|
|
305
|
+
};
|
|
306
|
+
_ibpsV2.set(id, p);
|
|
307
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
308
|
+
}
|
|
309
|
+
function _ibpCheckP(from, to) {
|
|
310
|
+
const a = _ibpTrans.get(from);
|
|
311
|
+
if (!a || !a.has(to))
|
|
312
|
+
throw new Error(`invalid iter budget profile transition ${from} → ${to}`);
|
|
313
|
+
}
|
|
314
|
+
function _ibpCountActive(owner) {
|
|
315
|
+
let n = 0;
|
|
316
|
+
for (const p of _ibpsV2.values())
|
|
317
|
+
if (
|
|
318
|
+
p.owner === owner &&
|
|
319
|
+
p.status === ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE
|
|
320
|
+
)
|
|
321
|
+
n++;
|
|
322
|
+
return n;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function activateIterBudgetProfileV2(id) {
|
|
326
|
+
const p = _ibpsV2.get(id);
|
|
327
|
+
if (!p) throw new Error(`iter budget profile ${id} not found`);
|
|
328
|
+
_ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE);
|
|
329
|
+
const recovery = p.status === ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
|
|
330
|
+
if (!recovery) {
|
|
331
|
+
const c = _ibpCountActive(p.owner);
|
|
332
|
+
if (c >= _ibpMaxActivePerOwner)
|
|
333
|
+
throw new Error(
|
|
334
|
+
`max active iter budget profiles per owner (${_ibpMaxActivePerOwner}) reached for ${p.owner}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
const now = Date.now();
|
|
338
|
+
p.status = ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE;
|
|
339
|
+
p.updatedAt = now;
|
|
340
|
+
p.lastTouchedAt = now;
|
|
341
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
342
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
343
|
+
}
|
|
344
|
+
export function pauseIterBudgetProfileV2(id) {
|
|
345
|
+
const p = _ibpsV2.get(id);
|
|
346
|
+
if (!p) throw new Error(`iter budget profile ${id} not found`);
|
|
347
|
+
_ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED);
|
|
348
|
+
p.status = ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
|
|
349
|
+
p.updatedAt = Date.now();
|
|
350
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
351
|
+
}
|
|
352
|
+
export function exhaustIterBudgetProfileV2(id) {
|
|
353
|
+
const p = _ibpsV2.get(id);
|
|
354
|
+
if (!p) throw new Error(`iter budget profile ${id} not found`);
|
|
355
|
+
_ibpCheckP(p.status, ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED);
|
|
356
|
+
const now = Date.now();
|
|
357
|
+
p.status = ITER_BUDGET_PROFILE_MATURITY_V2.EXHAUSTED;
|
|
358
|
+
p.updatedAt = now;
|
|
359
|
+
if (!p.exhaustedAt) p.exhaustedAt = now;
|
|
360
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
361
|
+
}
|
|
362
|
+
export function touchIterBudgetProfileV2(id) {
|
|
363
|
+
const p = _ibpsV2.get(id);
|
|
364
|
+
if (!p) throw new Error(`iter budget profile ${id} not found`);
|
|
365
|
+
if (_ibpTerminal.has(p.status))
|
|
366
|
+
throw new Error(`cannot touch terminal iter budget profile ${id}`);
|
|
367
|
+
const now = Date.now();
|
|
368
|
+
p.lastTouchedAt = now;
|
|
369
|
+
p.updatedAt = now;
|
|
370
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
371
|
+
}
|
|
372
|
+
export function getIterBudgetProfileV2(id) {
|
|
373
|
+
const p = _ibpsV2.get(id);
|
|
374
|
+
if (!p) return null;
|
|
375
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
376
|
+
}
|
|
377
|
+
export function listIterBudgetProfilesV2() {
|
|
378
|
+
return [..._ibpsV2.values()].map((p) => ({
|
|
379
|
+
...p,
|
|
380
|
+
metadata: { ...p.metadata },
|
|
381
|
+
}));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function _irCountPending(profileId) {
|
|
385
|
+
let n = 0;
|
|
386
|
+
for (const r of _irsV2.values())
|
|
387
|
+
if (
|
|
388
|
+
r.profileId === profileId &&
|
|
389
|
+
(r.status === ITER_RUN_LIFECYCLE_V2.QUEUED ||
|
|
390
|
+
r.status === ITER_RUN_LIFECYCLE_V2.RUNNING)
|
|
391
|
+
)
|
|
392
|
+
n++;
|
|
393
|
+
return n;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export function createIterRunV2({ id, profileId, goal, metadata } = {}) {
|
|
397
|
+
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
398
|
+
if (!profileId || typeof profileId !== "string")
|
|
399
|
+
throw new Error("profileId is required");
|
|
400
|
+
if (_irsV2.has(id)) throw new Error(`iter run ${id} already exists`);
|
|
401
|
+
if (!_ibpsV2.has(profileId))
|
|
402
|
+
throw new Error(`iter budget profile ${profileId} not found`);
|
|
403
|
+
const pending = _irCountPending(profileId);
|
|
404
|
+
if (pending >= _ibpMaxPendingRunsPerProfile)
|
|
405
|
+
throw new Error(
|
|
406
|
+
`max pending iter runs per profile (${_ibpMaxPendingRunsPerProfile}) reached for ${profileId}`,
|
|
407
|
+
);
|
|
408
|
+
const now = Date.now();
|
|
409
|
+
const r = {
|
|
410
|
+
id,
|
|
411
|
+
profileId,
|
|
412
|
+
goal: goal || "",
|
|
413
|
+
status: ITER_RUN_LIFECYCLE_V2.QUEUED,
|
|
414
|
+
createdAt: now,
|
|
415
|
+
updatedAt: now,
|
|
416
|
+
startedAt: null,
|
|
417
|
+
settledAt: null,
|
|
418
|
+
metadata: { ...(metadata || {}) },
|
|
419
|
+
};
|
|
420
|
+
_irsV2.set(id, r);
|
|
421
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
422
|
+
}
|
|
423
|
+
function _irCheckR(from, to) {
|
|
424
|
+
const a = _irTrans.get(from);
|
|
425
|
+
if (!a || !a.has(to))
|
|
426
|
+
throw new Error(`invalid iter run transition ${from} → ${to}`);
|
|
427
|
+
}
|
|
428
|
+
export function startIterRunV2(id) {
|
|
429
|
+
const r = _irsV2.get(id);
|
|
430
|
+
if (!r) throw new Error(`iter run ${id} not found`);
|
|
431
|
+
_irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.RUNNING);
|
|
432
|
+
const now = Date.now();
|
|
433
|
+
r.status = ITER_RUN_LIFECYCLE_V2.RUNNING;
|
|
434
|
+
r.updatedAt = now;
|
|
435
|
+
if (!r.startedAt) r.startedAt = now;
|
|
436
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
437
|
+
}
|
|
438
|
+
export function completeIterRunV2(id) {
|
|
439
|
+
const r = _irsV2.get(id);
|
|
440
|
+
if (!r) throw new Error(`iter run ${id} not found`);
|
|
441
|
+
_irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.COMPLETED);
|
|
442
|
+
const now = Date.now();
|
|
443
|
+
r.status = ITER_RUN_LIFECYCLE_V2.COMPLETED;
|
|
444
|
+
r.updatedAt = now;
|
|
445
|
+
if (!r.settledAt) r.settledAt = now;
|
|
446
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
447
|
+
}
|
|
448
|
+
export function failIterRunV2(id, reason) {
|
|
449
|
+
const r = _irsV2.get(id);
|
|
450
|
+
if (!r) throw new Error(`iter run ${id} not found`);
|
|
451
|
+
_irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.FAILED);
|
|
452
|
+
const now = Date.now();
|
|
453
|
+
r.status = ITER_RUN_LIFECYCLE_V2.FAILED;
|
|
454
|
+
r.updatedAt = now;
|
|
455
|
+
if (!r.settledAt) r.settledAt = now;
|
|
456
|
+
if (reason) r.metadata.failReason = String(reason);
|
|
457
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
458
|
+
}
|
|
459
|
+
export function cancelIterRunV2(id, reason) {
|
|
460
|
+
const r = _irsV2.get(id);
|
|
461
|
+
if (!r) throw new Error(`iter run ${id} not found`);
|
|
462
|
+
_irCheckR(r.status, ITER_RUN_LIFECYCLE_V2.CANCELLED);
|
|
463
|
+
const now = Date.now();
|
|
464
|
+
r.status = ITER_RUN_LIFECYCLE_V2.CANCELLED;
|
|
465
|
+
r.updatedAt = now;
|
|
466
|
+
if (!r.settledAt) r.settledAt = now;
|
|
467
|
+
if (reason) r.metadata.cancelReason = String(reason);
|
|
468
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
469
|
+
}
|
|
470
|
+
export function getIterRunV2(id) {
|
|
471
|
+
const r = _irsV2.get(id);
|
|
472
|
+
if (!r) return null;
|
|
473
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
474
|
+
}
|
|
475
|
+
export function listIterRunsV2() {
|
|
476
|
+
return [..._irsV2.values()].map((r) => ({
|
|
477
|
+
...r,
|
|
478
|
+
metadata: { ...r.metadata },
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export function autoPauseIdleIterBudgetProfilesV2({ now } = {}) {
|
|
483
|
+
const t = now ?? Date.now();
|
|
484
|
+
const flipped = [];
|
|
485
|
+
for (const p of _ibpsV2.values())
|
|
486
|
+
if (
|
|
487
|
+
p.status === ITER_BUDGET_PROFILE_MATURITY_V2.ACTIVE &&
|
|
488
|
+
t - p.lastTouchedAt >= _ibpIdleMs
|
|
489
|
+
) {
|
|
490
|
+
p.status = ITER_BUDGET_PROFILE_MATURITY_V2.PAUSED;
|
|
491
|
+
p.updatedAt = t;
|
|
492
|
+
flipped.push(p.id);
|
|
493
|
+
}
|
|
494
|
+
return { flipped, count: flipped.length };
|
|
495
|
+
}
|
|
496
|
+
export function autoFailStuckIterRunsV2({ now } = {}) {
|
|
497
|
+
const t = now ?? Date.now();
|
|
498
|
+
const flipped = [];
|
|
499
|
+
for (const r of _irsV2.values())
|
|
500
|
+
if (
|
|
501
|
+
r.status === ITER_RUN_LIFECYCLE_V2.RUNNING &&
|
|
502
|
+
r.startedAt != null &&
|
|
503
|
+
t - r.startedAt >= _irStuckMs
|
|
504
|
+
) {
|
|
505
|
+
r.status = ITER_RUN_LIFECYCLE_V2.FAILED;
|
|
506
|
+
r.updatedAt = t;
|
|
507
|
+
if (!r.settledAt) r.settledAt = t;
|
|
508
|
+
r.metadata.failReason = "auto-fail-stuck";
|
|
509
|
+
flipped.push(r.id);
|
|
510
|
+
}
|
|
511
|
+
return { flipped, count: flipped.length };
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export function getIterationBudgetGovStatsV2() {
|
|
515
|
+
const profilesByStatus = {};
|
|
516
|
+
for (const s of Object.values(ITER_BUDGET_PROFILE_MATURITY_V2))
|
|
517
|
+
profilesByStatus[s] = 0;
|
|
518
|
+
for (const p of _ibpsV2.values()) profilesByStatus[p.status]++;
|
|
519
|
+
const runsByStatus = {};
|
|
520
|
+
for (const s of Object.values(ITER_RUN_LIFECYCLE_V2)) runsByStatus[s] = 0;
|
|
521
|
+
for (const r of _irsV2.values()) runsByStatus[r.status]++;
|
|
522
|
+
return {
|
|
523
|
+
totalIterBudgetProfilesV2: _ibpsV2.size,
|
|
524
|
+
totalIterRunsV2: _irsV2.size,
|
|
525
|
+
maxActiveIterBudgetProfilesPerOwner: _ibpMaxActivePerOwner,
|
|
526
|
+
maxPendingIterRunsPerProfile: _ibpMaxPendingRunsPerProfile,
|
|
527
|
+
iterBudgetProfileIdleMs: _ibpIdleMs,
|
|
528
|
+
iterRunStuckMs: _irStuckMs,
|
|
529
|
+
profilesByStatus,
|
|
530
|
+
runsByStatus,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
@@ -960,3 +960,336 @@ export function _resetStateV2() {
|
|
|
960
960
|
_entityStaleMsV2 = KG_DEFAULT_ENTITY_STALE_MS;
|
|
961
961
|
_relationStaleMsV2 = KG_DEFAULT_RELATION_STALE_MS;
|
|
962
962
|
}
|
|
963
|
+
|
|
964
|
+
// =====================================================================
|
|
965
|
+
// knowledge-graph V2 governance overlay (iter16)
|
|
966
|
+
// =====================================================================
|
|
967
|
+
export const KGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
968
|
+
PENDING: "pending",
|
|
969
|
+
ACTIVE: "active",
|
|
970
|
+
STALE: "stale",
|
|
971
|
+
ARCHIVED: "archived",
|
|
972
|
+
});
|
|
973
|
+
export const KGOV_IMPORT_LIFECYCLE_V2 = Object.freeze({
|
|
974
|
+
QUEUED: "queued",
|
|
975
|
+
IMPORTING: "importing",
|
|
976
|
+
IMPORTED: "imported",
|
|
977
|
+
FAILED: "failed",
|
|
978
|
+
CANCELLED: "cancelled",
|
|
979
|
+
});
|
|
980
|
+
const _kgovPTrans = new Map([
|
|
981
|
+
[
|
|
982
|
+
KGOV_PROFILE_MATURITY_V2.PENDING,
|
|
983
|
+
new Set([
|
|
984
|
+
KGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
985
|
+
KGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
986
|
+
]),
|
|
987
|
+
],
|
|
988
|
+
[
|
|
989
|
+
KGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
990
|
+
new Set([
|
|
991
|
+
KGOV_PROFILE_MATURITY_V2.STALE,
|
|
992
|
+
KGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
993
|
+
]),
|
|
994
|
+
],
|
|
995
|
+
[
|
|
996
|
+
KGOV_PROFILE_MATURITY_V2.STALE,
|
|
997
|
+
new Set([
|
|
998
|
+
KGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
999
|
+
KGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1000
|
+
]),
|
|
1001
|
+
],
|
|
1002
|
+
[KGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1003
|
+
]);
|
|
1004
|
+
const _kgovPTerminal = new Set([KGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1005
|
+
const _kgovJTrans = new Map([
|
|
1006
|
+
[
|
|
1007
|
+
KGOV_IMPORT_LIFECYCLE_V2.QUEUED,
|
|
1008
|
+
new Set([
|
|
1009
|
+
KGOV_IMPORT_LIFECYCLE_V2.IMPORTING,
|
|
1010
|
+
KGOV_IMPORT_LIFECYCLE_V2.CANCELLED,
|
|
1011
|
+
]),
|
|
1012
|
+
],
|
|
1013
|
+
[
|
|
1014
|
+
KGOV_IMPORT_LIFECYCLE_V2.IMPORTING,
|
|
1015
|
+
new Set([
|
|
1016
|
+
KGOV_IMPORT_LIFECYCLE_V2.IMPORTED,
|
|
1017
|
+
KGOV_IMPORT_LIFECYCLE_V2.FAILED,
|
|
1018
|
+
KGOV_IMPORT_LIFECYCLE_V2.CANCELLED,
|
|
1019
|
+
]),
|
|
1020
|
+
],
|
|
1021
|
+
[KGOV_IMPORT_LIFECYCLE_V2.IMPORTED, new Set()],
|
|
1022
|
+
[KGOV_IMPORT_LIFECYCLE_V2.FAILED, new Set()],
|
|
1023
|
+
[KGOV_IMPORT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1024
|
+
]);
|
|
1025
|
+
const _kgovPsV2 = new Map();
|
|
1026
|
+
const _kgovJsV2 = new Map();
|
|
1027
|
+
let _kgovMaxActive = 6,
|
|
1028
|
+
_kgovMaxPending = 20,
|
|
1029
|
+
_kgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1030
|
+
_kgovStuckMs = 60 * 1000;
|
|
1031
|
+
function _kgovPos(n, label) {
|
|
1032
|
+
const v = Math.floor(Number(n));
|
|
1033
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1034
|
+
throw new Error(`${label} must be positive integer`);
|
|
1035
|
+
return v;
|
|
1036
|
+
}
|
|
1037
|
+
function _kgovCheckP(from, to) {
|
|
1038
|
+
const a = _kgovPTrans.get(from);
|
|
1039
|
+
if (!a || !a.has(to))
|
|
1040
|
+
throw new Error(`invalid kgov profile transition ${from} → ${to}`);
|
|
1041
|
+
}
|
|
1042
|
+
function _kgovCheckJ(from, to) {
|
|
1043
|
+
const a = _kgovJTrans.get(from);
|
|
1044
|
+
if (!a || !a.has(to))
|
|
1045
|
+
throw new Error(`invalid kgov import transition ${from} → ${to}`);
|
|
1046
|
+
}
|
|
1047
|
+
function _kgovCountActive(owner) {
|
|
1048
|
+
let c = 0;
|
|
1049
|
+
for (const p of _kgovPsV2.values())
|
|
1050
|
+
if (p.owner === owner && p.status === KGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
1051
|
+
return c;
|
|
1052
|
+
}
|
|
1053
|
+
function _kgovCountPending(profileId) {
|
|
1054
|
+
let c = 0;
|
|
1055
|
+
for (const j of _kgovJsV2.values())
|
|
1056
|
+
if (
|
|
1057
|
+
j.profileId === profileId &&
|
|
1058
|
+
(j.status === KGOV_IMPORT_LIFECYCLE_V2.QUEUED ||
|
|
1059
|
+
j.status === KGOV_IMPORT_LIFECYCLE_V2.IMPORTING)
|
|
1060
|
+
)
|
|
1061
|
+
c++;
|
|
1062
|
+
return c;
|
|
1063
|
+
}
|
|
1064
|
+
export function setMaxActiveKgovProfilesPerOwnerV2(n) {
|
|
1065
|
+
_kgovMaxActive = _kgovPos(n, "maxActiveKgovProfilesPerOwner");
|
|
1066
|
+
}
|
|
1067
|
+
export function getMaxActiveKgovProfilesPerOwnerV2() {
|
|
1068
|
+
return _kgovMaxActive;
|
|
1069
|
+
}
|
|
1070
|
+
export function setMaxPendingKgovImportsPerProfileV2(n) {
|
|
1071
|
+
_kgovMaxPending = _kgovPos(n, "maxPendingKgovImportsPerProfile");
|
|
1072
|
+
}
|
|
1073
|
+
export function getMaxPendingKgovImportsPerProfileV2() {
|
|
1074
|
+
return _kgovMaxPending;
|
|
1075
|
+
}
|
|
1076
|
+
export function setKgovProfileIdleMsV2(n) {
|
|
1077
|
+
_kgovIdleMs = _kgovPos(n, "kgovProfileIdleMs");
|
|
1078
|
+
}
|
|
1079
|
+
export function getKgovProfileIdleMsV2() {
|
|
1080
|
+
return _kgovIdleMs;
|
|
1081
|
+
}
|
|
1082
|
+
export function setKgovImportStuckMsV2(n) {
|
|
1083
|
+
_kgovStuckMs = _kgovPos(n, "kgovImportStuckMs");
|
|
1084
|
+
}
|
|
1085
|
+
export function getKgovImportStuckMsV2() {
|
|
1086
|
+
return _kgovStuckMs;
|
|
1087
|
+
}
|
|
1088
|
+
export function _resetStateKnowledgeGraphV2() {
|
|
1089
|
+
_kgovPsV2.clear();
|
|
1090
|
+
_kgovJsV2.clear();
|
|
1091
|
+
_kgovMaxActive = 6;
|
|
1092
|
+
_kgovMaxPending = 20;
|
|
1093
|
+
_kgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1094
|
+
_kgovStuckMs = 60 * 1000;
|
|
1095
|
+
}
|
|
1096
|
+
export function registerKgovProfileV2({ id, owner, namespace, metadata } = {}) {
|
|
1097
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1098
|
+
if (_kgovPsV2.has(id)) throw new Error(`kgov profile ${id} already exists`);
|
|
1099
|
+
const now = Date.now();
|
|
1100
|
+
const p = {
|
|
1101
|
+
id,
|
|
1102
|
+
owner,
|
|
1103
|
+
namespace: namespace || "default",
|
|
1104
|
+
status: KGOV_PROFILE_MATURITY_V2.PENDING,
|
|
1105
|
+
createdAt: now,
|
|
1106
|
+
updatedAt: now,
|
|
1107
|
+
lastTouchedAt: now,
|
|
1108
|
+
activatedAt: null,
|
|
1109
|
+
archivedAt: null,
|
|
1110
|
+
metadata: { ...(metadata || {}) },
|
|
1111
|
+
};
|
|
1112
|
+
_kgovPsV2.set(id, p);
|
|
1113
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1114
|
+
}
|
|
1115
|
+
export function activateKgovProfileV2(id) {
|
|
1116
|
+
const p = _kgovPsV2.get(id);
|
|
1117
|
+
if (!p) throw new Error(`kgov profile ${id} not found`);
|
|
1118
|
+
const isInitial = p.status === KGOV_PROFILE_MATURITY_V2.PENDING;
|
|
1119
|
+
_kgovCheckP(p.status, KGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1120
|
+
if (isInitial && _kgovCountActive(p.owner) >= _kgovMaxActive)
|
|
1121
|
+
throw new Error(`max active kgov profiles for owner ${p.owner} reached`);
|
|
1122
|
+
const now = Date.now();
|
|
1123
|
+
p.status = KGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1124
|
+
p.updatedAt = now;
|
|
1125
|
+
p.lastTouchedAt = now;
|
|
1126
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1127
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1128
|
+
}
|
|
1129
|
+
export function staleKgovProfileV2(id) {
|
|
1130
|
+
const p = _kgovPsV2.get(id);
|
|
1131
|
+
if (!p) throw new Error(`kgov profile ${id} not found`);
|
|
1132
|
+
_kgovCheckP(p.status, KGOV_PROFILE_MATURITY_V2.STALE);
|
|
1133
|
+
p.status = KGOV_PROFILE_MATURITY_V2.STALE;
|
|
1134
|
+
p.updatedAt = Date.now();
|
|
1135
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1136
|
+
}
|
|
1137
|
+
export function archiveKgovProfileV2(id) {
|
|
1138
|
+
const p = _kgovPsV2.get(id);
|
|
1139
|
+
if (!p) throw new Error(`kgov profile ${id} not found`);
|
|
1140
|
+
_kgovCheckP(p.status, KGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1141
|
+
const now = Date.now();
|
|
1142
|
+
p.status = KGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1143
|
+
p.updatedAt = now;
|
|
1144
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1145
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1146
|
+
}
|
|
1147
|
+
export function touchKgovProfileV2(id) {
|
|
1148
|
+
const p = _kgovPsV2.get(id);
|
|
1149
|
+
if (!p) throw new Error(`kgov profile ${id} not found`);
|
|
1150
|
+
if (_kgovPTerminal.has(p.status))
|
|
1151
|
+
throw new Error(`cannot touch terminal kgov profile ${id}`);
|
|
1152
|
+
const now = Date.now();
|
|
1153
|
+
p.lastTouchedAt = now;
|
|
1154
|
+
p.updatedAt = now;
|
|
1155
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1156
|
+
}
|
|
1157
|
+
export function getKgovProfileV2(id) {
|
|
1158
|
+
const p = _kgovPsV2.get(id);
|
|
1159
|
+
if (!p) return null;
|
|
1160
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1161
|
+
}
|
|
1162
|
+
export function listKgovProfilesV2() {
|
|
1163
|
+
return [..._kgovPsV2.values()].map((p) => ({
|
|
1164
|
+
...p,
|
|
1165
|
+
metadata: { ...p.metadata },
|
|
1166
|
+
}));
|
|
1167
|
+
}
|
|
1168
|
+
export function createKgovImportV2({ id, profileId, source, metadata } = {}) {
|
|
1169
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1170
|
+
if (_kgovJsV2.has(id)) throw new Error(`kgov import ${id} already exists`);
|
|
1171
|
+
if (!_kgovPsV2.has(profileId))
|
|
1172
|
+
throw new Error(`kgov profile ${profileId} not found`);
|
|
1173
|
+
if (_kgovCountPending(profileId) >= _kgovMaxPending)
|
|
1174
|
+
throw new Error(
|
|
1175
|
+
`max pending kgov imports for profile ${profileId} reached`,
|
|
1176
|
+
);
|
|
1177
|
+
const now = Date.now();
|
|
1178
|
+
const j = {
|
|
1179
|
+
id,
|
|
1180
|
+
profileId,
|
|
1181
|
+
source: source || "",
|
|
1182
|
+
status: KGOV_IMPORT_LIFECYCLE_V2.QUEUED,
|
|
1183
|
+
createdAt: now,
|
|
1184
|
+
updatedAt: now,
|
|
1185
|
+
startedAt: null,
|
|
1186
|
+
settledAt: null,
|
|
1187
|
+
metadata: { ...(metadata || {}) },
|
|
1188
|
+
};
|
|
1189
|
+
_kgovJsV2.set(id, j);
|
|
1190
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1191
|
+
}
|
|
1192
|
+
export function importingKgovImportV2(id) {
|
|
1193
|
+
const j = _kgovJsV2.get(id);
|
|
1194
|
+
if (!j) throw new Error(`kgov import ${id} not found`);
|
|
1195
|
+
_kgovCheckJ(j.status, KGOV_IMPORT_LIFECYCLE_V2.IMPORTING);
|
|
1196
|
+
const now = Date.now();
|
|
1197
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.IMPORTING;
|
|
1198
|
+
j.updatedAt = now;
|
|
1199
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1200
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1201
|
+
}
|
|
1202
|
+
export function completeImportKgovV2(id) {
|
|
1203
|
+
const j = _kgovJsV2.get(id);
|
|
1204
|
+
if (!j) throw new Error(`kgov import ${id} not found`);
|
|
1205
|
+
_kgovCheckJ(j.status, KGOV_IMPORT_LIFECYCLE_V2.IMPORTED);
|
|
1206
|
+
const now = Date.now();
|
|
1207
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.IMPORTED;
|
|
1208
|
+
j.updatedAt = now;
|
|
1209
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1210
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1211
|
+
}
|
|
1212
|
+
export function failKgovImportV2(id, reason) {
|
|
1213
|
+
const j = _kgovJsV2.get(id);
|
|
1214
|
+
if (!j) throw new Error(`kgov import ${id} not found`);
|
|
1215
|
+
_kgovCheckJ(j.status, KGOV_IMPORT_LIFECYCLE_V2.FAILED);
|
|
1216
|
+
const now = Date.now();
|
|
1217
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.FAILED;
|
|
1218
|
+
j.updatedAt = now;
|
|
1219
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1220
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1221
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1222
|
+
}
|
|
1223
|
+
export function cancelKgovImportV2(id, reason) {
|
|
1224
|
+
const j = _kgovJsV2.get(id);
|
|
1225
|
+
if (!j) throw new Error(`kgov import ${id} not found`);
|
|
1226
|
+
_kgovCheckJ(j.status, KGOV_IMPORT_LIFECYCLE_V2.CANCELLED);
|
|
1227
|
+
const now = Date.now();
|
|
1228
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.CANCELLED;
|
|
1229
|
+
j.updatedAt = now;
|
|
1230
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1231
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1232
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1233
|
+
}
|
|
1234
|
+
export function getKgovImportV2(id) {
|
|
1235
|
+
const j = _kgovJsV2.get(id);
|
|
1236
|
+
if (!j) return null;
|
|
1237
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1238
|
+
}
|
|
1239
|
+
export function listKgovImportsV2() {
|
|
1240
|
+
return [..._kgovJsV2.values()].map((j) => ({
|
|
1241
|
+
...j,
|
|
1242
|
+
metadata: { ...j.metadata },
|
|
1243
|
+
}));
|
|
1244
|
+
}
|
|
1245
|
+
export function autoStaleIdleKgovProfilesV2({ now } = {}) {
|
|
1246
|
+
const t = now ?? Date.now();
|
|
1247
|
+
const flipped = [];
|
|
1248
|
+
for (const p of _kgovPsV2.values())
|
|
1249
|
+
if (
|
|
1250
|
+
p.status === KGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1251
|
+
t - p.lastTouchedAt >= _kgovIdleMs
|
|
1252
|
+
) {
|
|
1253
|
+
p.status = KGOV_PROFILE_MATURITY_V2.STALE;
|
|
1254
|
+
p.updatedAt = t;
|
|
1255
|
+
flipped.push(p.id);
|
|
1256
|
+
}
|
|
1257
|
+
return { flipped, count: flipped.length };
|
|
1258
|
+
}
|
|
1259
|
+
export function autoFailStuckKgovImportsV2({ now } = {}) {
|
|
1260
|
+
const t = now ?? Date.now();
|
|
1261
|
+
const flipped = [];
|
|
1262
|
+
for (const j of _kgovJsV2.values())
|
|
1263
|
+
if (
|
|
1264
|
+
j.status === KGOV_IMPORT_LIFECYCLE_V2.IMPORTING &&
|
|
1265
|
+
j.startedAt != null &&
|
|
1266
|
+
t - j.startedAt >= _kgovStuckMs
|
|
1267
|
+
) {
|
|
1268
|
+
j.status = KGOV_IMPORT_LIFECYCLE_V2.FAILED;
|
|
1269
|
+
j.updatedAt = t;
|
|
1270
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1271
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1272
|
+
flipped.push(j.id);
|
|
1273
|
+
}
|
|
1274
|
+
return { flipped, count: flipped.length };
|
|
1275
|
+
}
|
|
1276
|
+
export function getKnowledgeGraphGovStatsV2() {
|
|
1277
|
+
const profilesByStatus = {};
|
|
1278
|
+
for (const v of Object.values(KGOV_PROFILE_MATURITY_V2))
|
|
1279
|
+
profilesByStatus[v] = 0;
|
|
1280
|
+
for (const p of _kgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1281
|
+
const importsByStatus = {};
|
|
1282
|
+
for (const v of Object.values(KGOV_IMPORT_LIFECYCLE_V2))
|
|
1283
|
+
importsByStatus[v] = 0;
|
|
1284
|
+
for (const j of _kgovJsV2.values()) importsByStatus[j.status]++;
|
|
1285
|
+
return {
|
|
1286
|
+
totalKgovProfilesV2: _kgovPsV2.size,
|
|
1287
|
+
totalKgovImportsV2: _kgovJsV2.size,
|
|
1288
|
+
maxActiveKgovProfilesPerOwner: _kgovMaxActive,
|
|
1289
|
+
maxPendingKgovImportsPerProfile: _kgovMaxPending,
|
|
1290
|
+
kgovProfileIdleMs: _kgovIdleMs,
|
|
1291
|
+
kgovImportStuckMs: _kgovStuckMs,
|
|
1292
|
+
profilesByStatus,
|
|
1293
|
+
importsByStatus,
|
|
1294
|
+
};
|
|
1295
|
+
}
|