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
|
@@ -184,81 +184,342 @@ export function createServiceContainer() {
|
|
|
184
184
|
|
|
185
185
|
// ===== V2 Surface: Service Container governance overlay (CLI v0.141.0) =====
|
|
186
186
|
export const SVC_CONTAINER_MATURITY_V2 = Object.freeze({
|
|
187
|
-
PENDING: "pending",
|
|
187
|
+
PENDING: "pending",
|
|
188
|
+
ACTIVE: "active",
|
|
189
|
+
DEGRADED: "degraded",
|
|
190
|
+
DECOMMISSIONED: "decommissioned",
|
|
188
191
|
});
|
|
189
192
|
export const SVC_RESOLUTION_LIFECYCLE_V2 = Object.freeze({
|
|
190
|
-
QUEUED: "queued",
|
|
193
|
+
QUEUED: "queued",
|
|
194
|
+
RESOLVING: "resolving",
|
|
195
|
+
RESOLVED: "resolved",
|
|
196
|
+
FAILED: "failed",
|
|
197
|
+
CANCELLED: "cancelled",
|
|
191
198
|
});
|
|
192
199
|
const _svcCTrans = new Map([
|
|
193
|
-
[
|
|
194
|
-
|
|
195
|
-
|
|
200
|
+
[
|
|
201
|
+
SVC_CONTAINER_MATURITY_V2.PENDING,
|
|
202
|
+
new Set([
|
|
203
|
+
SVC_CONTAINER_MATURITY_V2.ACTIVE,
|
|
204
|
+
SVC_CONTAINER_MATURITY_V2.DECOMMISSIONED,
|
|
205
|
+
]),
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
SVC_CONTAINER_MATURITY_V2.ACTIVE,
|
|
209
|
+
new Set([
|
|
210
|
+
SVC_CONTAINER_MATURITY_V2.DEGRADED,
|
|
211
|
+
SVC_CONTAINER_MATURITY_V2.DECOMMISSIONED,
|
|
212
|
+
]),
|
|
213
|
+
],
|
|
214
|
+
[
|
|
215
|
+
SVC_CONTAINER_MATURITY_V2.DEGRADED,
|
|
216
|
+
new Set([
|
|
217
|
+
SVC_CONTAINER_MATURITY_V2.ACTIVE,
|
|
218
|
+
SVC_CONTAINER_MATURITY_V2.DECOMMISSIONED,
|
|
219
|
+
]),
|
|
220
|
+
],
|
|
196
221
|
[SVC_CONTAINER_MATURITY_V2.DECOMMISSIONED, new Set()],
|
|
197
222
|
]);
|
|
198
223
|
const _svcCTerminal = new Set([SVC_CONTAINER_MATURITY_V2.DECOMMISSIONED]);
|
|
199
224
|
const _svcRTrans = new Map([
|
|
200
|
-
[
|
|
201
|
-
|
|
225
|
+
[
|
|
226
|
+
SVC_RESOLUTION_LIFECYCLE_V2.QUEUED,
|
|
227
|
+
new Set([
|
|
228
|
+
SVC_RESOLUTION_LIFECYCLE_V2.RESOLVING,
|
|
229
|
+
SVC_RESOLUTION_LIFECYCLE_V2.CANCELLED,
|
|
230
|
+
]),
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
SVC_RESOLUTION_LIFECYCLE_V2.RESOLVING,
|
|
234
|
+
new Set([
|
|
235
|
+
SVC_RESOLUTION_LIFECYCLE_V2.RESOLVED,
|
|
236
|
+
SVC_RESOLUTION_LIFECYCLE_V2.FAILED,
|
|
237
|
+
SVC_RESOLUTION_LIFECYCLE_V2.CANCELLED,
|
|
238
|
+
]),
|
|
239
|
+
],
|
|
202
240
|
[SVC_RESOLUTION_LIFECYCLE_V2.RESOLVED, new Set()],
|
|
203
241
|
[SVC_RESOLUTION_LIFECYCLE_V2.FAILED, new Set()],
|
|
204
242
|
[SVC_RESOLUTION_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
205
243
|
]);
|
|
206
244
|
const _svcCsV2 = new Map();
|
|
207
245
|
const _svcRsV2 = new Map();
|
|
208
|
-
let _svcMaxActivePerOwner = 8,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
246
|
+
let _svcMaxActivePerOwner = 8,
|
|
247
|
+
_svcMaxPendingResPerContainer = 25,
|
|
248
|
+
_svcIdleMs = 60 * 60 * 1000,
|
|
249
|
+
_svcStuckMs = 30 * 1000;
|
|
250
|
+
function _svcPos(n, label) {
|
|
251
|
+
const v = Math.floor(Number(n));
|
|
252
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
253
|
+
throw new Error(`${label} must be positive integer`);
|
|
254
|
+
return v;
|
|
255
|
+
}
|
|
256
|
+
function _svcCheckC(from, to) {
|
|
257
|
+
const a = _svcCTrans.get(from);
|
|
258
|
+
if (!a || !a.has(to))
|
|
259
|
+
throw new Error(`invalid svc container transition ${from} → ${to}`);
|
|
260
|
+
}
|
|
261
|
+
function _svcCheckR(from, to) {
|
|
262
|
+
const a = _svcRTrans.get(from);
|
|
263
|
+
if (!a || !a.has(to))
|
|
264
|
+
throw new Error(`invalid svc resolution transition ${from} → ${to}`);
|
|
265
|
+
}
|
|
266
|
+
export function setMaxActiveSvcContainersPerOwnerV2(n) {
|
|
267
|
+
_svcMaxActivePerOwner = _svcPos(n, "maxActiveSvcContainersPerOwner");
|
|
268
|
+
}
|
|
269
|
+
export function getMaxActiveSvcContainersPerOwnerV2() {
|
|
270
|
+
return _svcMaxActivePerOwner;
|
|
271
|
+
}
|
|
272
|
+
export function setMaxPendingSvcResolutionsPerContainerV2(n) {
|
|
273
|
+
_svcMaxPendingResPerContainer = _svcPos(
|
|
274
|
+
n,
|
|
275
|
+
"maxPendingSvcResolutionsPerContainer",
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
export function getMaxPendingSvcResolutionsPerContainerV2() {
|
|
279
|
+
return _svcMaxPendingResPerContainer;
|
|
280
|
+
}
|
|
281
|
+
export function setSvcContainerIdleMsV2(n) {
|
|
282
|
+
_svcIdleMs = _svcPos(n, "svcContainerIdleMs");
|
|
283
|
+
}
|
|
284
|
+
export function getSvcContainerIdleMsV2() {
|
|
285
|
+
return _svcIdleMs;
|
|
286
|
+
}
|
|
287
|
+
export function setSvcResolutionStuckMsV2(n) {
|
|
288
|
+
_svcStuckMs = _svcPos(n, "svcResolutionStuckMs");
|
|
289
|
+
}
|
|
290
|
+
export function getSvcResolutionStuckMsV2() {
|
|
291
|
+
return _svcStuckMs;
|
|
292
|
+
}
|
|
293
|
+
export function _resetStateServiceContainerV2() {
|
|
294
|
+
_svcCsV2.clear();
|
|
295
|
+
_svcRsV2.clear();
|
|
296
|
+
_svcMaxActivePerOwner = 8;
|
|
297
|
+
_svcMaxPendingResPerContainer = 25;
|
|
298
|
+
_svcIdleMs = 60 * 60 * 1000;
|
|
299
|
+
_svcStuckMs = 30 * 1000;
|
|
300
|
+
}
|
|
221
301
|
export function registerSvcContainerV2({ id, owner, scope, metadata } = {}) {
|
|
222
|
-
if (!id) throw new Error("svc container id required");
|
|
223
|
-
if (
|
|
302
|
+
if (!id) throw new Error("svc container id required");
|
|
303
|
+
if (!owner) throw new Error("svc container owner required");
|
|
304
|
+
if (_svcCsV2.has(id))
|
|
305
|
+
throw new Error(`svc container ${id} already registered`);
|
|
224
306
|
const now = Date.now();
|
|
225
|
-
const c = {
|
|
226
|
-
|
|
307
|
+
const c = {
|
|
308
|
+
id,
|
|
309
|
+
owner,
|
|
310
|
+
scope: scope || "default",
|
|
311
|
+
status: SVC_CONTAINER_MATURITY_V2.PENDING,
|
|
312
|
+
createdAt: now,
|
|
313
|
+
updatedAt: now,
|
|
314
|
+
activatedAt: null,
|
|
315
|
+
decommissionedAt: null,
|
|
316
|
+
lastTouchedAt: now,
|
|
317
|
+
metadata: { ...(metadata || {}) },
|
|
318
|
+
};
|
|
319
|
+
_svcCsV2.set(id, c);
|
|
320
|
+
return { ...c, metadata: { ...c.metadata } };
|
|
321
|
+
}
|
|
322
|
+
function _svcCountActive(owner) {
|
|
323
|
+
let n = 0;
|
|
324
|
+
for (const c of _svcCsV2.values())
|
|
325
|
+
if (c.owner === owner && c.status === SVC_CONTAINER_MATURITY_V2.ACTIVE) n++;
|
|
326
|
+
return n;
|
|
227
327
|
}
|
|
228
|
-
function _svcCountActive(owner) { let n = 0; for (const c of _svcCsV2.values()) if (c.owner === owner && c.status === SVC_CONTAINER_MATURITY_V2.ACTIVE) n++; return n; }
|
|
229
328
|
export function activateSvcContainerV2(id) {
|
|
230
|
-
const c = _svcCsV2.get(id);
|
|
329
|
+
const c = _svcCsV2.get(id);
|
|
330
|
+
if (!c) throw new Error(`svc container ${id} not found`);
|
|
231
331
|
_svcCheckC(c.status, SVC_CONTAINER_MATURITY_V2.ACTIVE);
|
|
232
332
|
const recovery = c.status === SVC_CONTAINER_MATURITY_V2.DEGRADED;
|
|
233
|
-
if (!recovery && _svcCountActive(c.owner) >= _svcMaxActivePerOwner)
|
|
234
|
-
|
|
333
|
+
if (!recovery && _svcCountActive(c.owner) >= _svcMaxActivePerOwner)
|
|
334
|
+
throw new Error(`max active svc containers for owner ${c.owner} reached`);
|
|
335
|
+
const now = Date.now();
|
|
336
|
+
c.status = SVC_CONTAINER_MATURITY_V2.ACTIVE;
|
|
337
|
+
c.updatedAt = now;
|
|
338
|
+
c.lastTouchedAt = now;
|
|
339
|
+
if (!c.activatedAt) c.activatedAt = now;
|
|
340
|
+
return { ...c, metadata: { ...c.metadata } };
|
|
341
|
+
}
|
|
342
|
+
export function degradeSvcContainerV2(id) {
|
|
343
|
+
const c = _svcCsV2.get(id);
|
|
344
|
+
if (!c) throw new Error(`svc container ${id} not found`);
|
|
345
|
+
_svcCheckC(c.status, SVC_CONTAINER_MATURITY_V2.DEGRADED);
|
|
346
|
+
c.status = SVC_CONTAINER_MATURITY_V2.DEGRADED;
|
|
347
|
+
c.updatedAt = Date.now();
|
|
348
|
+
return { ...c, metadata: { ...c.metadata } };
|
|
349
|
+
}
|
|
350
|
+
export function decommissionSvcContainerV2(id) {
|
|
351
|
+
const c = _svcCsV2.get(id);
|
|
352
|
+
if (!c) throw new Error(`svc container ${id} not found`);
|
|
353
|
+
_svcCheckC(c.status, SVC_CONTAINER_MATURITY_V2.DECOMMISSIONED);
|
|
354
|
+
const now = Date.now();
|
|
355
|
+
c.status = SVC_CONTAINER_MATURITY_V2.DECOMMISSIONED;
|
|
356
|
+
c.updatedAt = now;
|
|
357
|
+
if (!c.decommissionedAt) c.decommissionedAt = now;
|
|
358
|
+
return { ...c, metadata: { ...c.metadata } };
|
|
359
|
+
}
|
|
360
|
+
export function touchSvcContainerV2(id) {
|
|
361
|
+
const c = _svcCsV2.get(id);
|
|
362
|
+
if (!c) throw new Error(`svc container ${id} not found`);
|
|
363
|
+
if (_svcCTerminal.has(c.status))
|
|
364
|
+
throw new Error(`cannot touch terminal svc container ${id}`);
|
|
365
|
+
const now = Date.now();
|
|
366
|
+
c.lastTouchedAt = now;
|
|
367
|
+
c.updatedAt = now;
|
|
368
|
+
return { ...c, metadata: { ...c.metadata } };
|
|
369
|
+
}
|
|
370
|
+
export function getSvcContainerV2(id) {
|
|
371
|
+
const c = _svcCsV2.get(id);
|
|
372
|
+
if (!c) return null;
|
|
235
373
|
return { ...c, metadata: { ...c.metadata } };
|
|
236
374
|
}
|
|
237
|
-
export function
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
375
|
+
export function listSvcContainersV2() {
|
|
376
|
+
return [..._svcCsV2.values()].map((c) => ({
|
|
377
|
+
...c,
|
|
378
|
+
metadata: { ...c.metadata },
|
|
379
|
+
}));
|
|
380
|
+
}
|
|
381
|
+
function _svcCountPending(containerId) {
|
|
382
|
+
let n = 0;
|
|
383
|
+
for (const r of _svcRsV2.values())
|
|
384
|
+
if (
|
|
385
|
+
r.containerId === containerId &&
|
|
386
|
+
(r.status === SVC_RESOLUTION_LIFECYCLE_V2.QUEUED ||
|
|
387
|
+
r.status === SVC_RESOLUTION_LIFECYCLE_V2.RESOLVING)
|
|
388
|
+
)
|
|
389
|
+
n++;
|
|
390
|
+
return n;
|
|
391
|
+
}
|
|
392
|
+
export function createSvcResolutionV2({
|
|
393
|
+
id,
|
|
394
|
+
containerId,
|
|
395
|
+
token,
|
|
396
|
+
metadata,
|
|
397
|
+
} = {}) {
|
|
398
|
+
if (!id) throw new Error("svc resolution id required");
|
|
399
|
+
if (!containerId) throw new Error("svc resolution containerId required");
|
|
245
400
|
if (_svcRsV2.has(id)) throw new Error(`svc resolution ${id} already exists`);
|
|
246
|
-
if (!_svcCsV2.has(containerId))
|
|
247
|
-
|
|
401
|
+
if (!_svcCsV2.has(containerId))
|
|
402
|
+
throw new Error(`svc container ${containerId} not found`);
|
|
403
|
+
if (_svcCountPending(containerId) >= _svcMaxPendingResPerContainer)
|
|
404
|
+
throw new Error(
|
|
405
|
+
`max pending svc resolutions for container ${containerId} reached`,
|
|
406
|
+
);
|
|
248
407
|
const now = Date.now();
|
|
249
|
-
const r = {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
408
|
+
const r = {
|
|
409
|
+
id,
|
|
410
|
+
containerId,
|
|
411
|
+
token: token || "",
|
|
412
|
+
status: SVC_RESOLUTION_LIFECYCLE_V2.QUEUED,
|
|
413
|
+
createdAt: now,
|
|
414
|
+
updatedAt: now,
|
|
415
|
+
startedAt: null,
|
|
416
|
+
settledAt: null,
|
|
417
|
+
metadata: { ...(metadata || {}) },
|
|
418
|
+
};
|
|
419
|
+
_svcRsV2.set(id, r);
|
|
420
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
421
|
+
}
|
|
422
|
+
export function resolvingSvcResolutionV2(id) {
|
|
423
|
+
const r = _svcRsV2.get(id);
|
|
424
|
+
if (!r) throw new Error(`svc resolution ${id} not found`);
|
|
425
|
+
_svcCheckR(r.status, SVC_RESOLUTION_LIFECYCLE_V2.RESOLVING);
|
|
426
|
+
const now = Date.now();
|
|
427
|
+
r.status = SVC_RESOLUTION_LIFECYCLE_V2.RESOLVING;
|
|
428
|
+
r.updatedAt = now;
|
|
429
|
+
if (!r.startedAt) r.startedAt = now;
|
|
430
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
431
|
+
}
|
|
432
|
+
export function resolveSvcResolutionV2(id) {
|
|
433
|
+
const r = _svcRsV2.get(id);
|
|
434
|
+
if (!r) throw new Error(`svc resolution ${id} not found`);
|
|
435
|
+
_svcCheckR(r.status, SVC_RESOLUTION_LIFECYCLE_V2.RESOLVED);
|
|
436
|
+
const now = Date.now();
|
|
437
|
+
r.status = SVC_RESOLUTION_LIFECYCLE_V2.RESOLVED;
|
|
438
|
+
r.updatedAt = now;
|
|
439
|
+
if (!r.settledAt) r.settledAt = now;
|
|
440
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
441
|
+
}
|
|
442
|
+
export function failSvcResolutionV2(id, reason) {
|
|
443
|
+
const r = _svcRsV2.get(id);
|
|
444
|
+
if (!r) throw new Error(`svc resolution ${id} not found`);
|
|
445
|
+
_svcCheckR(r.status, SVC_RESOLUTION_LIFECYCLE_V2.FAILED);
|
|
446
|
+
const now = Date.now();
|
|
447
|
+
r.status = SVC_RESOLUTION_LIFECYCLE_V2.FAILED;
|
|
448
|
+
r.updatedAt = now;
|
|
449
|
+
if (!r.settledAt) r.settledAt = now;
|
|
450
|
+
if (reason) r.metadata.failReason = String(reason);
|
|
451
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
452
|
+
}
|
|
453
|
+
export function cancelSvcResolutionV2(id, reason) {
|
|
454
|
+
const r = _svcRsV2.get(id);
|
|
455
|
+
if (!r) throw new Error(`svc resolution ${id} not found`);
|
|
456
|
+
_svcCheckR(r.status, SVC_RESOLUTION_LIFECYCLE_V2.CANCELLED);
|
|
457
|
+
const now = Date.now();
|
|
458
|
+
r.status = SVC_RESOLUTION_LIFECYCLE_V2.CANCELLED;
|
|
459
|
+
r.updatedAt = now;
|
|
460
|
+
if (!r.settledAt) r.settledAt = now;
|
|
461
|
+
if (reason) r.metadata.cancelReason = String(reason);
|
|
462
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
463
|
+
}
|
|
464
|
+
export function getSvcResolutionV2(id) {
|
|
465
|
+
const r = _svcRsV2.get(id);
|
|
466
|
+
if (!r) return null;
|
|
467
|
+
return { ...r, metadata: { ...r.metadata } };
|
|
468
|
+
}
|
|
469
|
+
export function listSvcResolutionsV2() {
|
|
470
|
+
return [..._svcRsV2.values()].map((r) => ({
|
|
471
|
+
...r,
|
|
472
|
+
metadata: { ...r.metadata },
|
|
473
|
+
}));
|
|
474
|
+
}
|
|
475
|
+
export function autoDegradeIdleSvcContainersV2({ now } = {}) {
|
|
476
|
+
const t = now ?? Date.now();
|
|
477
|
+
const flipped = [];
|
|
478
|
+
for (const c of _svcCsV2.values())
|
|
479
|
+
if (
|
|
480
|
+
c.status === SVC_CONTAINER_MATURITY_V2.ACTIVE &&
|
|
481
|
+
t - c.lastTouchedAt >= _svcIdleMs
|
|
482
|
+
) {
|
|
483
|
+
c.status = SVC_CONTAINER_MATURITY_V2.DEGRADED;
|
|
484
|
+
c.updatedAt = t;
|
|
485
|
+
flipped.push(c.id);
|
|
486
|
+
}
|
|
487
|
+
return { flipped, count: flipped.length };
|
|
488
|
+
}
|
|
489
|
+
export function autoFailStuckSvcResolutionsV2({ now } = {}) {
|
|
490
|
+
const t = now ?? Date.now();
|
|
491
|
+
const flipped = [];
|
|
492
|
+
for (const r of _svcRsV2.values())
|
|
493
|
+
if (
|
|
494
|
+
r.status === SVC_RESOLUTION_LIFECYCLE_V2.RESOLVING &&
|
|
495
|
+
r.startedAt != null &&
|
|
496
|
+
t - r.startedAt >= _svcStuckMs
|
|
497
|
+
) {
|
|
498
|
+
r.status = SVC_RESOLUTION_LIFECYCLE_V2.FAILED;
|
|
499
|
+
r.updatedAt = t;
|
|
500
|
+
if (!r.settledAt) r.settledAt = t;
|
|
501
|
+
r.metadata.failReason = "auto-fail-stuck";
|
|
502
|
+
flipped.push(r.id);
|
|
503
|
+
}
|
|
504
|
+
return { flipped, count: flipped.length };
|
|
505
|
+
}
|
|
260
506
|
export function getServiceContainerGovStatsV2() {
|
|
261
|
-
const containersByStatus = {};
|
|
262
|
-
|
|
263
|
-
|
|
507
|
+
const containersByStatus = {};
|
|
508
|
+
for (const v of Object.values(SVC_CONTAINER_MATURITY_V2))
|
|
509
|
+
containersByStatus[v] = 0;
|
|
510
|
+
for (const c of _svcCsV2.values()) containersByStatus[c.status]++;
|
|
511
|
+
const resolutionsByStatus = {};
|
|
512
|
+
for (const v of Object.values(SVC_RESOLUTION_LIFECYCLE_V2))
|
|
513
|
+
resolutionsByStatus[v] = 0;
|
|
514
|
+
for (const r of _svcRsV2.values()) resolutionsByStatus[r.status]++;
|
|
515
|
+
return {
|
|
516
|
+
totalSvcContainersV2: _svcCsV2.size,
|
|
517
|
+
totalSvcResolutionsV2: _svcRsV2.size,
|
|
518
|
+
maxActiveSvcContainersPerOwner: _svcMaxActivePerOwner,
|
|
519
|
+
maxPendingSvcResolutionsPerContainer: _svcMaxPendingResPerContainer,
|
|
520
|
+
svcContainerIdleMs: _svcIdleMs,
|
|
521
|
+
svcResolutionStuckMs: _svcStuckMs,
|
|
522
|
+
containersByStatus,
|
|
523
|
+
resolutionsByStatus,
|
|
524
|
+
};
|
|
264
525
|
}
|