chainlesschain 0.143.0 → 0.152.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-manager.js +334 -0
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/web-fetch.js
CHANGED
|
@@ -225,81 +225,322 @@ export const _deps = { http, https };
|
|
|
225
225
|
|
|
226
226
|
// ===== V2 Surface: Web Fetch governance overlay (CLI v0.142.0) =====
|
|
227
227
|
export const WFET_TARGET_MATURITY_V2 = Object.freeze({
|
|
228
|
-
PENDING: "pending",
|
|
228
|
+
PENDING: "pending",
|
|
229
|
+
ACTIVE: "active",
|
|
230
|
+
DEGRADED: "degraded",
|
|
231
|
+
RETIRED: "retired",
|
|
229
232
|
});
|
|
230
233
|
export const WFET_JOB_LIFECYCLE_V2 = Object.freeze({
|
|
231
|
-
QUEUED: "queued",
|
|
234
|
+
QUEUED: "queued",
|
|
235
|
+
FETCHING: "fetching",
|
|
236
|
+
SUCCEEDED: "succeeded",
|
|
237
|
+
FAILED: "failed",
|
|
238
|
+
CANCELLED: "cancelled",
|
|
232
239
|
});
|
|
233
240
|
const _wfetTTrans = new Map([
|
|
234
|
-
[
|
|
235
|
-
|
|
236
|
-
|
|
241
|
+
[
|
|
242
|
+
WFET_TARGET_MATURITY_V2.PENDING,
|
|
243
|
+
new Set([WFET_TARGET_MATURITY_V2.ACTIVE, WFET_TARGET_MATURITY_V2.RETIRED]),
|
|
244
|
+
],
|
|
245
|
+
[
|
|
246
|
+
WFET_TARGET_MATURITY_V2.ACTIVE,
|
|
247
|
+
new Set([
|
|
248
|
+
WFET_TARGET_MATURITY_V2.DEGRADED,
|
|
249
|
+
WFET_TARGET_MATURITY_V2.RETIRED,
|
|
250
|
+
]),
|
|
251
|
+
],
|
|
252
|
+
[
|
|
253
|
+
WFET_TARGET_MATURITY_V2.DEGRADED,
|
|
254
|
+
new Set([WFET_TARGET_MATURITY_V2.ACTIVE, WFET_TARGET_MATURITY_V2.RETIRED]),
|
|
255
|
+
],
|
|
237
256
|
[WFET_TARGET_MATURITY_V2.RETIRED, new Set()],
|
|
238
257
|
]);
|
|
239
258
|
const _wfetTTerminal = new Set([WFET_TARGET_MATURITY_V2.RETIRED]);
|
|
240
259
|
const _wfetJTrans = new Map([
|
|
241
|
-
[
|
|
242
|
-
|
|
260
|
+
[
|
|
261
|
+
WFET_JOB_LIFECYCLE_V2.QUEUED,
|
|
262
|
+
new Set([WFET_JOB_LIFECYCLE_V2.FETCHING, WFET_JOB_LIFECYCLE_V2.CANCELLED]),
|
|
263
|
+
],
|
|
264
|
+
[
|
|
265
|
+
WFET_JOB_LIFECYCLE_V2.FETCHING,
|
|
266
|
+
new Set([
|
|
267
|
+
WFET_JOB_LIFECYCLE_V2.SUCCEEDED,
|
|
268
|
+
WFET_JOB_LIFECYCLE_V2.FAILED,
|
|
269
|
+
WFET_JOB_LIFECYCLE_V2.CANCELLED,
|
|
270
|
+
]),
|
|
271
|
+
],
|
|
243
272
|
[WFET_JOB_LIFECYCLE_V2.SUCCEEDED, new Set()],
|
|
244
273
|
[WFET_JOB_LIFECYCLE_V2.FAILED, new Set()],
|
|
245
274
|
[WFET_JOB_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
246
275
|
]);
|
|
247
276
|
const _wfetTsV2 = new Map();
|
|
248
277
|
const _wfetJsV2 = new Map();
|
|
249
|
-
let _wfetMaxActive = 12,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
278
|
+
let _wfetMaxActive = 12,
|
|
279
|
+
_wfetMaxPending = 30,
|
|
280
|
+
_wfetIdleMs = 7 * 24 * 60 * 60 * 1000,
|
|
281
|
+
_wfetStuckMs = 60 * 1000;
|
|
282
|
+
function _wfetPos(n, label) {
|
|
283
|
+
const v = Math.floor(Number(n));
|
|
284
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
285
|
+
throw new Error(`${label} must be positive integer`);
|
|
286
|
+
return v;
|
|
287
|
+
}
|
|
288
|
+
function _wfetCheckT(from, to) {
|
|
289
|
+
const a = _wfetTTrans.get(from);
|
|
290
|
+
if (!a || !a.has(to))
|
|
291
|
+
throw new Error(`invalid wfet target transition ${from} → ${to}`);
|
|
292
|
+
}
|
|
293
|
+
function _wfetCheckJ(from, to) {
|
|
294
|
+
const a = _wfetJTrans.get(from);
|
|
295
|
+
if (!a || !a.has(to))
|
|
296
|
+
throw new Error(`invalid wfet job transition ${from} → ${to}`);
|
|
297
|
+
}
|
|
298
|
+
export function setMaxActiveWfetTargetsPerOwnerV2(n) {
|
|
299
|
+
_wfetMaxActive = _wfetPos(n, "maxActiveWfetTargetsPerOwner");
|
|
300
|
+
}
|
|
301
|
+
export function getMaxActiveWfetTargetsPerOwnerV2() {
|
|
302
|
+
return _wfetMaxActive;
|
|
303
|
+
}
|
|
304
|
+
export function setMaxPendingWfetJobsPerTargetV2(n) {
|
|
305
|
+
_wfetMaxPending = _wfetPos(n, "maxPendingWfetJobsPerTarget");
|
|
306
|
+
}
|
|
307
|
+
export function getMaxPendingWfetJobsPerTargetV2() {
|
|
308
|
+
return _wfetMaxPending;
|
|
309
|
+
}
|
|
310
|
+
export function setWfetTargetIdleMsV2(n) {
|
|
311
|
+
_wfetIdleMs = _wfetPos(n, "wfetTargetIdleMs");
|
|
312
|
+
}
|
|
313
|
+
export function getWfetTargetIdleMsV2() {
|
|
314
|
+
return _wfetIdleMs;
|
|
315
|
+
}
|
|
316
|
+
export function setWfetJobStuckMsV2(n) {
|
|
317
|
+
_wfetStuckMs = _wfetPos(n, "wfetJobStuckMs");
|
|
318
|
+
}
|
|
319
|
+
export function getWfetJobStuckMsV2() {
|
|
320
|
+
return _wfetStuckMs;
|
|
321
|
+
}
|
|
322
|
+
export function _resetStateWebFetchV2() {
|
|
323
|
+
_wfetTsV2.clear();
|
|
324
|
+
_wfetJsV2.clear();
|
|
325
|
+
_wfetMaxActive = 12;
|
|
326
|
+
_wfetMaxPending = 30;
|
|
327
|
+
_wfetIdleMs = 7 * 24 * 60 * 60 * 1000;
|
|
328
|
+
_wfetStuckMs = 60 * 1000;
|
|
329
|
+
}
|
|
262
330
|
export function registerWfetTargetV2({ id, owner, baseUrl, metadata } = {}) {
|
|
263
|
-
if (!id) throw new Error("wfet target id required");
|
|
264
|
-
if (
|
|
331
|
+
if (!id) throw new Error("wfet target id required");
|
|
332
|
+
if (!owner) throw new Error("wfet target owner required");
|
|
333
|
+
if (_wfetTsV2.has(id))
|
|
334
|
+
throw new Error(`wfet target ${id} already registered`);
|
|
265
335
|
const now = Date.now();
|
|
266
|
-
const t = {
|
|
267
|
-
|
|
336
|
+
const t = {
|
|
337
|
+
id,
|
|
338
|
+
owner,
|
|
339
|
+
baseUrl: baseUrl || "",
|
|
340
|
+
status: WFET_TARGET_MATURITY_V2.PENDING,
|
|
341
|
+
createdAt: now,
|
|
342
|
+
updatedAt: now,
|
|
343
|
+
activatedAt: null,
|
|
344
|
+
retiredAt: null,
|
|
345
|
+
lastTouchedAt: now,
|
|
346
|
+
metadata: { ...(metadata || {}) },
|
|
347
|
+
};
|
|
348
|
+
_wfetTsV2.set(id, t);
|
|
349
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
350
|
+
}
|
|
351
|
+
function _wfetCountActive(owner) {
|
|
352
|
+
let n = 0;
|
|
353
|
+
for (const t of _wfetTsV2.values())
|
|
354
|
+
if (t.owner === owner && t.status === WFET_TARGET_MATURITY_V2.ACTIVE) n++;
|
|
355
|
+
return n;
|
|
268
356
|
}
|
|
269
|
-
function _wfetCountActive(owner) { let n = 0; for (const t of _wfetTsV2.values()) if (t.owner === owner && t.status === WFET_TARGET_MATURITY_V2.ACTIVE) n++; return n; }
|
|
270
357
|
export function activateWfetTargetV2(id) {
|
|
271
|
-
const t = _wfetTsV2.get(id);
|
|
358
|
+
const t = _wfetTsV2.get(id);
|
|
359
|
+
if (!t) throw new Error(`wfet target ${id} not found`);
|
|
272
360
|
_wfetCheckT(t.status, WFET_TARGET_MATURITY_V2.ACTIVE);
|
|
273
361
|
const recovery = t.status === WFET_TARGET_MATURITY_V2.DEGRADED;
|
|
274
|
-
if (!recovery && _wfetCountActive(t.owner) >= _wfetMaxActive)
|
|
275
|
-
|
|
362
|
+
if (!recovery && _wfetCountActive(t.owner) >= _wfetMaxActive)
|
|
363
|
+
throw new Error(`max active wfet targets for owner ${t.owner} reached`);
|
|
364
|
+
const now = Date.now();
|
|
365
|
+
t.status = WFET_TARGET_MATURITY_V2.ACTIVE;
|
|
366
|
+
t.updatedAt = now;
|
|
367
|
+
t.lastTouchedAt = now;
|
|
368
|
+
if (!t.activatedAt) t.activatedAt = now;
|
|
369
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
370
|
+
}
|
|
371
|
+
export function degradeWfetTargetV2(id) {
|
|
372
|
+
const t = _wfetTsV2.get(id);
|
|
373
|
+
if (!t) throw new Error(`wfet target ${id} not found`);
|
|
374
|
+
_wfetCheckT(t.status, WFET_TARGET_MATURITY_V2.DEGRADED);
|
|
375
|
+
t.status = WFET_TARGET_MATURITY_V2.DEGRADED;
|
|
376
|
+
t.updatedAt = Date.now();
|
|
377
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
378
|
+
}
|
|
379
|
+
export function retireWfetTargetV2(id) {
|
|
380
|
+
const t = _wfetTsV2.get(id);
|
|
381
|
+
if (!t) throw new Error(`wfet target ${id} not found`);
|
|
382
|
+
_wfetCheckT(t.status, WFET_TARGET_MATURITY_V2.RETIRED);
|
|
383
|
+
const now = Date.now();
|
|
384
|
+
t.status = WFET_TARGET_MATURITY_V2.RETIRED;
|
|
385
|
+
t.updatedAt = now;
|
|
386
|
+
if (!t.retiredAt) t.retiredAt = now;
|
|
387
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
388
|
+
}
|
|
389
|
+
export function touchWfetTargetV2(id) {
|
|
390
|
+
const t = _wfetTsV2.get(id);
|
|
391
|
+
if (!t) throw new Error(`wfet target ${id} not found`);
|
|
392
|
+
if (_wfetTTerminal.has(t.status))
|
|
393
|
+
throw new Error(`cannot touch terminal wfet target ${id}`);
|
|
394
|
+
const now = Date.now();
|
|
395
|
+
t.lastTouchedAt = now;
|
|
396
|
+
t.updatedAt = now;
|
|
397
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
398
|
+
}
|
|
399
|
+
export function getWfetTargetV2(id) {
|
|
400
|
+
const t = _wfetTsV2.get(id);
|
|
401
|
+
if (!t) return null;
|
|
276
402
|
return { ...t, metadata: { ...t.metadata } };
|
|
277
403
|
}
|
|
278
|
-
export function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
404
|
+
export function listWfetTargetsV2() {
|
|
405
|
+
return [..._wfetTsV2.values()].map((t) => ({
|
|
406
|
+
...t,
|
|
407
|
+
metadata: { ...t.metadata },
|
|
408
|
+
}));
|
|
409
|
+
}
|
|
410
|
+
function _wfetCountPending(targetId) {
|
|
411
|
+
let n = 0;
|
|
412
|
+
for (const j of _wfetJsV2.values())
|
|
413
|
+
if (
|
|
414
|
+
j.targetId === targetId &&
|
|
415
|
+
(j.status === WFET_JOB_LIFECYCLE_V2.QUEUED ||
|
|
416
|
+
j.status === WFET_JOB_LIFECYCLE_V2.FETCHING)
|
|
417
|
+
)
|
|
418
|
+
n++;
|
|
419
|
+
return n;
|
|
420
|
+
}
|
|
284
421
|
export function createWfetJobV2({ id, targetId, kind, metadata } = {}) {
|
|
285
|
-
if (!id) throw new Error("wfet job id required");
|
|
422
|
+
if (!id) throw new Error("wfet job id required");
|
|
423
|
+
if (!targetId) throw new Error("wfet job targetId required");
|
|
286
424
|
if (_wfetJsV2.has(id)) throw new Error(`wfet job ${id} already exists`);
|
|
287
|
-
if (!_wfetTsV2.has(targetId))
|
|
288
|
-
|
|
425
|
+
if (!_wfetTsV2.has(targetId))
|
|
426
|
+
throw new Error(`wfet target ${targetId} not found`);
|
|
427
|
+
if (_wfetCountPending(targetId) >= _wfetMaxPending)
|
|
428
|
+
throw new Error(`max pending wfet jobs for target ${targetId} reached`);
|
|
429
|
+
const now = Date.now();
|
|
430
|
+
const j = {
|
|
431
|
+
id,
|
|
432
|
+
targetId,
|
|
433
|
+
kind: kind || "GET",
|
|
434
|
+
status: WFET_JOB_LIFECYCLE_V2.QUEUED,
|
|
435
|
+
createdAt: now,
|
|
436
|
+
updatedAt: now,
|
|
437
|
+
startedAt: null,
|
|
438
|
+
settledAt: null,
|
|
439
|
+
metadata: { ...(metadata || {}) },
|
|
440
|
+
};
|
|
441
|
+
_wfetJsV2.set(id, j);
|
|
442
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
443
|
+
}
|
|
444
|
+
export function fetchingWfetJobV2(id) {
|
|
445
|
+
const j = _wfetJsV2.get(id);
|
|
446
|
+
if (!j) throw new Error(`wfet job ${id} not found`);
|
|
447
|
+
_wfetCheckJ(j.status, WFET_JOB_LIFECYCLE_V2.FETCHING);
|
|
448
|
+
const now = Date.now();
|
|
449
|
+
j.status = WFET_JOB_LIFECYCLE_V2.FETCHING;
|
|
450
|
+
j.updatedAt = now;
|
|
451
|
+
if (!j.startedAt) j.startedAt = now;
|
|
452
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
453
|
+
}
|
|
454
|
+
export function succeedWfetJobV2(id) {
|
|
455
|
+
const j = _wfetJsV2.get(id);
|
|
456
|
+
if (!j) throw new Error(`wfet job ${id} not found`);
|
|
457
|
+
_wfetCheckJ(j.status, WFET_JOB_LIFECYCLE_V2.SUCCEEDED);
|
|
458
|
+
const now = Date.now();
|
|
459
|
+
j.status = WFET_JOB_LIFECYCLE_V2.SUCCEEDED;
|
|
460
|
+
j.updatedAt = now;
|
|
461
|
+
if (!j.settledAt) j.settledAt = now;
|
|
462
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
463
|
+
}
|
|
464
|
+
export function failWfetJobV2(id, reason) {
|
|
465
|
+
const j = _wfetJsV2.get(id);
|
|
466
|
+
if (!j) throw new Error(`wfet job ${id} not found`);
|
|
467
|
+
_wfetCheckJ(j.status, WFET_JOB_LIFECYCLE_V2.FAILED);
|
|
289
468
|
const now = Date.now();
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
export function cancelWfetJobV2(id, reason) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
469
|
+
j.status = WFET_JOB_LIFECYCLE_V2.FAILED;
|
|
470
|
+
j.updatedAt = now;
|
|
471
|
+
if (!j.settledAt) j.settledAt = now;
|
|
472
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
473
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
474
|
+
}
|
|
475
|
+
export function cancelWfetJobV2(id, reason) {
|
|
476
|
+
const j = _wfetJsV2.get(id);
|
|
477
|
+
if (!j) throw new Error(`wfet job ${id} not found`);
|
|
478
|
+
_wfetCheckJ(j.status, WFET_JOB_LIFECYCLE_V2.CANCELLED);
|
|
479
|
+
const now = Date.now();
|
|
480
|
+
j.status = WFET_JOB_LIFECYCLE_V2.CANCELLED;
|
|
481
|
+
j.updatedAt = now;
|
|
482
|
+
if (!j.settledAt) j.settledAt = now;
|
|
483
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
484
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
485
|
+
}
|
|
486
|
+
export function getWfetJobV2(id) {
|
|
487
|
+
const j = _wfetJsV2.get(id);
|
|
488
|
+
if (!j) return null;
|
|
489
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
490
|
+
}
|
|
491
|
+
export function listWfetJobsV2() {
|
|
492
|
+
return [..._wfetJsV2.values()].map((j) => ({
|
|
493
|
+
...j,
|
|
494
|
+
metadata: { ...j.metadata },
|
|
495
|
+
}));
|
|
496
|
+
}
|
|
497
|
+
export function autoDegradeIdleWfetTargetsV2({ now } = {}) {
|
|
498
|
+
const t = now ?? Date.now();
|
|
499
|
+
const flipped = [];
|
|
500
|
+
for (const x of _wfetTsV2.values())
|
|
501
|
+
if (
|
|
502
|
+
x.status === WFET_TARGET_MATURITY_V2.ACTIVE &&
|
|
503
|
+
t - x.lastTouchedAt >= _wfetIdleMs
|
|
504
|
+
) {
|
|
505
|
+
x.status = WFET_TARGET_MATURITY_V2.DEGRADED;
|
|
506
|
+
x.updatedAt = t;
|
|
507
|
+
flipped.push(x.id);
|
|
508
|
+
}
|
|
509
|
+
return { flipped, count: flipped.length };
|
|
510
|
+
}
|
|
511
|
+
export function autoFailStuckWfetJobsV2({ now } = {}) {
|
|
512
|
+
const t = now ?? Date.now();
|
|
513
|
+
const flipped = [];
|
|
514
|
+
for (const j of _wfetJsV2.values())
|
|
515
|
+
if (
|
|
516
|
+
j.status === WFET_JOB_LIFECYCLE_V2.FETCHING &&
|
|
517
|
+
j.startedAt != null &&
|
|
518
|
+
t - j.startedAt >= _wfetStuckMs
|
|
519
|
+
) {
|
|
520
|
+
j.status = WFET_JOB_LIFECYCLE_V2.FAILED;
|
|
521
|
+
j.updatedAt = t;
|
|
522
|
+
if (!j.settledAt) j.settledAt = t;
|
|
523
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
524
|
+
flipped.push(j.id);
|
|
525
|
+
}
|
|
526
|
+
return { flipped, count: flipped.length };
|
|
527
|
+
}
|
|
301
528
|
export function getWebFetchGovStatsV2() {
|
|
302
|
-
const targetsByStatus = {};
|
|
303
|
-
|
|
304
|
-
|
|
529
|
+
const targetsByStatus = {};
|
|
530
|
+
for (const v of Object.values(WFET_TARGET_MATURITY_V2))
|
|
531
|
+
targetsByStatus[v] = 0;
|
|
532
|
+
for (const t of _wfetTsV2.values()) targetsByStatus[t.status]++;
|
|
533
|
+
const jobsByStatus = {};
|
|
534
|
+
for (const v of Object.values(WFET_JOB_LIFECYCLE_V2)) jobsByStatus[v] = 0;
|
|
535
|
+
for (const j of _wfetJsV2.values()) jobsByStatus[j.status]++;
|
|
536
|
+
return {
|
|
537
|
+
totalWfetTargetsV2: _wfetTsV2.size,
|
|
538
|
+
totalWfetJobsV2: _wfetJsV2.size,
|
|
539
|
+
maxActiveWfetTargetsPerOwner: _wfetMaxActive,
|
|
540
|
+
maxPendingWfetJobsPerTarget: _wfetMaxPending,
|
|
541
|
+
wfetTargetIdleMs: _wfetIdleMs,
|
|
542
|
+
wfetJobStuckMs: _wfetStuckMs,
|
|
543
|
+
targetsByStatus,
|
|
544
|
+
jobsByStatus,
|
|
545
|
+
};
|
|
305
546
|
}
|