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
package/src/lib/skill-mcp.js
CHANGED
|
@@ -188,3 +188,339 @@ export async function unmountSkillMcpServers(mcpClient, mountedNames) {
|
|
|
188
188
|
|
|
189
189
|
return { unmounted, errors };
|
|
190
190
|
}
|
|
191
|
+
|
|
192
|
+
// =====================================================================
|
|
193
|
+
// skill-mcp V2 governance overlay (iter27)
|
|
194
|
+
// =====================================================================
|
|
195
|
+
export const SMCPGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
196
|
+
PENDING: "pending",
|
|
197
|
+
ACTIVE: "active",
|
|
198
|
+
STALE: "stale",
|
|
199
|
+
ARCHIVED: "archived",
|
|
200
|
+
});
|
|
201
|
+
export const SMCPGOV_CALL_LIFECYCLE_V2 = Object.freeze({
|
|
202
|
+
QUEUED: "queued",
|
|
203
|
+
INVOKING: "invoking",
|
|
204
|
+
INVOKED: "invoked",
|
|
205
|
+
FAILED: "failed",
|
|
206
|
+
CANCELLED: "cancelled",
|
|
207
|
+
});
|
|
208
|
+
const _smcpgovPTrans = new Map([
|
|
209
|
+
[
|
|
210
|
+
SMCPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
211
|
+
new Set([
|
|
212
|
+
SMCPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
213
|
+
SMCPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
214
|
+
]),
|
|
215
|
+
],
|
|
216
|
+
[
|
|
217
|
+
SMCPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
218
|
+
new Set([
|
|
219
|
+
SMCPGOV_PROFILE_MATURITY_V2.STALE,
|
|
220
|
+
SMCPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
221
|
+
]),
|
|
222
|
+
],
|
|
223
|
+
[
|
|
224
|
+
SMCPGOV_PROFILE_MATURITY_V2.STALE,
|
|
225
|
+
new Set([
|
|
226
|
+
SMCPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
227
|
+
SMCPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
228
|
+
]),
|
|
229
|
+
],
|
|
230
|
+
[SMCPGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
231
|
+
]);
|
|
232
|
+
const _smcpgovPTerminal = new Set([SMCPGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
233
|
+
const _smcpgovJTrans = new Map([
|
|
234
|
+
[
|
|
235
|
+
SMCPGOV_CALL_LIFECYCLE_V2.QUEUED,
|
|
236
|
+
new Set([
|
|
237
|
+
SMCPGOV_CALL_LIFECYCLE_V2.INVOKING,
|
|
238
|
+
SMCPGOV_CALL_LIFECYCLE_V2.CANCELLED,
|
|
239
|
+
]),
|
|
240
|
+
],
|
|
241
|
+
[
|
|
242
|
+
SMCPGOV_CALL_LIFECYCLE_V2.INVOKING,
|
|
243
|
+
new Set([
|
|
244
|
+
SMCPGOV_CALL_LIFECYCLE_V2.INVOKED,
|
|
245
|
+
SMCPGOV_CALL_LIFECYCLE_V2.FAILED,
|
|
246
|
+
SMCPGOV_CALL_LIFECYCLE_V2.CANCELLED,
|
|
247
|
+
]),
|
|
248
|
+
],
|
|
249
|
+
[SMCPGOV_CALL_LIFECYCLE_V2.INVOKED, new Set()],
|
|
250
|
+
[SMCPGOV_CALL_LIFECYCLE_V2.FAILED, new Set()],
|
|
251
|
+
[SMCPGOV_CALL_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
252
|
+
]);
|
|
253
|
+
const _smcpgovPsV2 = new Map();
|
|
254
|
+
const _smcpgovJsV2 = new Map();
|
|
255
|
+
let _smcpgovMaxActive = 6,
|
|
256
|
+
_smcpgovMaxPending = 15,
|
|
257
|
+
_smcpgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
258
|
+
_smcpgovStuckMs = 60 * 1000;
|
|
259
|
+
function _smcpgovPos(n, label) {
|
|
260
|
+
const v = Math.floor(Number(n));
|
|
261
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
262
|
+
throw new Error(`${label} must be positive integer`);
|
|
263
|
+
return v;
|
|
264
|
+
}
|
|
265
|
+
function _smcpgovCheckP(from, to) {
|
|
266
|
+
const a = _smcpgovPTrans.get(from);
|
|
267
|
+
if (!a || !a.has(to))
|
|
268
|
+
throw new Error(`invalid smcpgov profile transition ${from} → ${to}`);
|
|
269
|
+
}
|
|
270
|
+
function _smcpgovCheckJ(from, to) {
|
|
271
|
+
const a = _smcpgovJTrans.get(from);
|
|
272
|
+
if (!a || !a.has(to))
|
|
273
|
+
throw new Error(`invalid smcpgov call transition ${from} → ${to}`);
|
|
274
|
+
}
|
|
275
|
+
function _smcpgovCountActive(owner) {
|
|
276
|
+
let c = 0;
|
|
277
|
+
for (const p of _smcpgovPsV2.values())
|
|
278
|
+
if (p.owner === owner && p.status === SMCPGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
279
|
+
c++;
|
|
280
|
+
return c;
|
|
281
|
+
}
|
|
282
|
+
function _smcpgovCountPending(profileId) {
|
|
283
|
+
let c = 0;
|
|
284
|
+
for (const j of _smcpgovJsV2.values())
|
|
285
|
+
if (
|
|
286
|
+
j.profileId === profileId &&
|
|
287
|
+
(j.status === SMCPGOV_CALL_LIFECYCLE_V2.QUEUED ||
|
|
288
|
+
j.status === SMCPGOV_CALL_LIFECYCLE_V2.INVOKING)
|
|
289
|
+
)
|
|
290
|
+
c++;
|
|
291
|
+
return c;
|
|
292
|
+
}
|
|
293
|
+
export function setMaxActiveSmcpgovProfilesPerOwnerV2(n) {
|
|
294
|
+
_smcpgovMaxActive = _smcpgovPos(n, "maxActiveSmcpgovProfilesPerOwner");
|
|
295
|
+
}
|
|
296
|
+
export function getMaxActiveSmcpgovProfilesPerOwnerV2() {
|
|
297
|
+
return _smcpgovMaxActive;
|
|
298
|
+
}
|
|
299
|
+
export function setMaxPendingSmcpgovCallsPerProfileV2(n) {
|
|
300
|
+
_smcpgovMaxPending = _smcpgovPos(n, "maxPendingSmcpgovCallsPerProfile");
|
|
301
|
+
}
|
|
302
|
+
export function getMaxPendingSmcpgovCallsPerProfileV2() {
|
|
303
|
+
return _smcpgovMaxPending;
|
|
304
|
+
}
|
|
305
|
+
export function setSmcpgovProfileIdleMsV2(n) {
|
|
306
|
+
_smcpgovIdleMs = _smcpgovPos(n, "smcpgovProfileIdleMs");
|
|
307
|
+
}
|
|
308
|
+
export function getSmcpgovProfileIdleMsV2() {
|
|
309
|
+
return _smcpgovIdleMs;
|
|
310
|
+
}
|
|
311
|
+
export function setSmcpgovCallStuckMsV2(n) {
|
|
312
|
+
_smcpgovStuckMs = _smcpgovPos(n, "smcpgovCallStuckMs");
|
|
313
|
+
}
|
|
314
|
+
export function getSmcpgovCallStuckMsV2() {
|
|
315
|
+
return _smcpgovStuckMs;
|
|
316
|
+
}
|
|
317
|
+
export function _resetStateSkillMcpGovV2() {
|
|
318
|
+
_smcpgovPsV2.clear();
|
|
319
|
+
_smcpgovJsV2.clear();
|
|
320
|
+
_smcpgovMaxActive = 6;
|
|
321
|
+
_smcpgovMaxPending = 15;
|
|
322
|
+
_smcpgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
323
|
+
_smcpgovStuckMs = 60 * 1000;
|
|
324
|
+
}
|
|
325
|
+
export function registerSmcpgovProfileV2({ id, owner, server, metadata } = {}) {
|
|
326
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
327
|
+
if (_smcpgovPsV2.has(id))
|
|
328
|
+
throw new Error(`smcpgov profile ${id} already exists`);
|
|
329
|
+
const now = Date.now();
|
|
330
|
+
const p = {
|
|
331
|
+
id,
|
|
332
|
+
owner,
|
|
333
|
+
server: server || "default",
|
|
334
|
+
status: SMCPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
335
|
+
createdAt: now,
|
|
336
|
+
updatedAt: now,
|
|
337
|
+
lastTouchedAt: now,
|
|
338
|
+
activatedAt: null,
|
|
339
|
+
archivedAt: null,
|
|
340
|
+
metadata: { ...(metadata || {}) },
|
|
341
|
+
};
|
|
342
|
+
_smcpgovPsV2.set(id, p);
|
|
343
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
344
|
+
}
|
|
345
|
+
export function activateSmcpgovProfileV2(id) {
|
|
346
|
+
const p = _smcpgovPsV2.get(id);
|
|
347
|
+
if (!p) throw new Error(`smcpgov profile ${id} not found`);
|
|
348
|
+
const isInitial = p.status === SMCPGOV_PROFILE_MATURITY_V2.PENDING;
|
|
349
|
+
_smcpgovCheckP(p.status, SMCPGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
350
|
+
if (isInitial && _smcpgovCountActive(p.owner) >= _smcpgovMaxActive)
|
|
351
|
+
throw new Error(`max active smcpgov profiles for owner ${p.owner} reached`);
|
|
352
|
+
const now = Date.now();
|
|
353
|
+
p.status = SMCPGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
354
|
+
p.updatedAt = now;
|
|
355
|
+
p.lastTouchedAt = now;
|
|
356
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
357
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
358
|
+
}
|
|
359
|
+
export function staleSmcpgovProfileV2(id) {
|
|
360
|
+
const p = _smcpgovPsV2.get(id);
|
|
361
|
+
if (!p) throw new Error(`smcpgov profile ${id} not found`);
|
|
362
|
+
_smcpgovCheckP(p.status, SMCPGOV_PROFILE_MATURITY_V2.STALE);
|
|
363
|
+
p.status = SMCPGOV_PROFILE_MATURITY_V2.STALE;
|
|
364
|
+
p.updatedAt = Date.now();
|
|
365
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
366
|
+
}
|
|
367
|
+
export function archiveSmcpgovProfileV2(id) {
|
|
368
|
+
const p = _smcpgovPsV2.get(id);
|
|
369
|
+
if (!p) throw new Error(`smcpgov profile ${id} not found`);
|
|
370
|
+
_smcpgovCheckP(p.status, SMCPGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
371
|
+
const now = Date.now();
|
|
372
|
+
p.status = SMCPGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
373
|
+
p.updatedAt = now;
|
|
374
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
375
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
376
|
+
}
|
|
377
|
+
export function touchSmcpgovProfileV2(id) {
|
|
378
|
+
const p = _smcpgovPsV2.get(id);
|
|
379
|
+
if (!p) throw new Error(`smcpgov profile ${id} not found`);
|
|
380
|
+
if (_smcpgovPTerminal.has(p.status))
|
|
381
|
+
throw new Error(`cannot touch terminal smcpgov profile ${id}`);
|
|
382
|
+
const now = Date.now();
|
|
383
|
+
p.lastTouchedAt = now;
|
|
384
|
+
p.updatedAt = now;
|
|
385
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
386
|
+
}
|
|
387
|
+
export function getSmcpgovProfileV2(id) {
|
|
388
|
+
const p = _smcpgovPsV2.get(id);
|
|
389
|
+
if (!p) return null;
|
|
390
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
391
|
+
}
|
|
392
|
+
export function listSmcpgovProfilesV2() {
|
|
393
|
+
return [..._smcpgovPsV2.values()].map((p) => ({
|
|
394
|
+
...p,
|
|
395
|
+
metadata: { ...p.metadata },
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
export function createSmcpgovCallV2({ id, profileId, tool, metadata } = {}) {
|
|
399
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
400
|
+
if (_smcpgovJsV2.has(id))
|
|
401
|
+
throw new Error(`smcpgov call ${id} already exists`);
|
|
402
|
+
if (!_smcpgovPsV2.has(profileId))
|
|
403
|
+
throw new Error(`smcpgov profile ${profileId} not found`);
|
|
404
|
+
if (_smcpgovCountPending(profileId) >= _smcpgovMaxPending)
|
|
405
|
+
throw new Error(
|
|
406
|
+
`max pending smcpgov calls for profile ${profileId} reached`,
|
|
407
|
+
);
|
|
408
|
+
const now = Date.now();
|
|
409
|
+
const j = {
|
|
410
|
+
id,
|
|
411
|
+
profileId,
|
|
412
|
+
tool: tool || "",
|
|
413
|
+
status: SMCPGOV_CALL_LIFECYCLE_V2.QUEUED,
|
|
414
|
+
createdAt: now,
|
|
415
|
+
updatedAt: now,
|
|
416
|
+
startedAt: null,
|
|
417
|
+
settledAt: null,
|
|
418
|
+
metadata: { ...(metadata || {}) },
|
|
419
|
+
};
|
|
420
|
+
_smcpgovJsV2.set(id, j);
|
|
421
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
422
|
+
}
|
|
423
|
+
export function invokingSmcpgovCallV2(id) {
|
|
424
|
+
const j = _smcpgovJsV2.get(id);
|
|
425
|
+
if (!j) throw new Error(`smcpgov call ${id} not found`);
|
|
426
|
+
_smcpgovCheckJ(j.status, SMCPGOV_CALL_LIFECYCLE_V2.INVOKING);
|
|
427
|
+
const now = Date.now();
|
|
428
|
+
j.status = SMCPGOV_CALL_LIFECYCLE_V2.INVOKING;
|
|
429
|
+
j.updatedAt = now;
|
|
430
|
+
if (!j.startedAt) j.startedAt = now;
|
|
431
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
432
|
+
}
|
|
433
|
+
export function completeCallSmcpgovV2(id) {
|
|
434
|
+
const j = _smcpgovJsV2.get(id);
|
|
435
|
+
if (!j) throw new Error(`smcpgov call ${id} not found`);
|
|
436
|
+
_smcpgovCheckJ(j.status, SMCPGOV_CALL_LIFECYCLE_V2.INVOKED);
|
|
437
|
+
const now = Date.now();
|
|
438
|
+
j.status = SMCPGOV_CALL_LIFECYCLE_V2.INVOKED;
|
|
439
|
+
j.updatedAt = now;
|
|
440
|
+
if (!j.settledAt) j.settledAt = now;
|
|
441
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
442
|
+
}
|
|
443
|
+
export function failSmcpgovCallV2(id, reason) {
|
|
444
|
+
const j = _smcpgovJsV2.get(id);
|
|
445
|
+
if (!j) throw new Error(`smcpgov call ${id} not found`);
|
|
446
|
+
_smcpgovCheckJ(j.status, SMCPGOV_CALL_LIFECYCLE_V2.FAILED);
|
|
447
|
+
const now = Date.now();
|
|
448
|
+
j.status = SMCPGOV_CALL_LIFECYCLE_V2.FAILED;
|
|
449
|
+
j.updatedAt = now;
|
|
450
|
+
if (!j.settledAt) j.settledAt = now;
|
|
451
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
452
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
453
|
+
}
|
|
454
|
+
export function cancelSmcpgovCallV2(id, reason) {
|
|
455
|
+
const j = _smcpgovJsV2.get(id);
|
|
456
|
+
if (!j) throw new Error(`smcpgov call ${id} not found`);
|
|
457
|
+
_smcpgovCheckJ(j.status, SMCPGOV_CALL_LIFECYCLE_V2.CANCELLED);
|
|
458
|
+
const now = Date.now();
|
|
459
|
+
j.status = SMCPGOV_CALL_LIFECYCLE_V2.CANCELLED;
|
|
460
|
+
j.updatedAt = now;
|
|
461
|
+
if (!j.settledAt) j.settledAt = now;
|
|
462
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
463
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
464
|
+
}
|
|
465
|
+
export function getSmcpgovCallV2(id) {
|
|
466
|
+
const j = _smcpgovJsV2.get(id);
|
|
467
|
+
if (!j) return null;
|
|
468
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
469
|
+
}
|
|
470
|
+
export function listSmcpgovCallsV2() {
|
|
471
|
+
return [..._smcpgovJsV2.values()].map((j) => ({
|
|
472
|
+
...j,
|
|
473
|
+
metadata: { ...j.metadata },
|
|
474
|
+
}));
|
|
475
|
+
}
|
|
476
|
+
export function autoStaleIdleSmcpgovProfilesV2({ now } = {}) {
|
|
477
|
+
const t = now ?? Date.now();
|
|
478
|
+
const flipped = [];
|
|
479
|
+
for (const p of _smcpgovPsV2.values())
|
|
480
|
+
if (
|
|
481
|
+
p.status === SMCPGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
482
|
+
t - p.lastTouchedAt >= _smcpgovIdleMs
|
|
483
|
+
) {
|
|
484
|
+
p.status = SMCPGOV_PROFILE_MATURITY_V2.STALE;
|
|
485
|
+
p.updatedAt = t;
|
|
486
|
+
flipped.push(p.id);
|
|
487
|
+
}
|
|
488
|
+
return { flipped, count: flipped.length };
|
|
489
|
+
}
|
|
490
|
+
export function autoFailStuckSmcpgovCallsV2({ now } = {}) {
|
|
491
|
+
const t = now ?? Date.now();
|
|
492
|
+
const flipped = [];
|
|
493
|
+
for (const j of _smcpgovJsV2.values())
|
|
494
|
+
if (
|
|
495
|
+
j.status === SMCPGOV_CALL_LIFECYCLE_V2.INVOKING &&
|
|
496
|
+
j.startedAt != null &&
|
|
497
|
+
t - j.startedAt >= _smcpgovStuckMs
|
|
498
|
+
) {
|
|
499
|
+
j.status = SMCPGOV_CALL_LIFECYCLE_V2.FAILED;
|
|
500
|
+
j.updatedAt = t;
|
|
501
|
+
if (!j.settledAt) j.settledAt = t;
|
|
502
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
503
|
+
flipped.push(j.id);
|
|
504
|
+
}
|
|
505
|
+
return { flipped, count: flipped.length };
|
|
506
|
+
}
|
|
507
|
+
export function getSkillMcpGovStatsV2() {
|
|
508
|
+
const profilesByStatus = {};
|
|
509
|
+
for (const v of Object.values(SMCPGOV_PROFILE_MATURITY_V2))
|
|
510
|
+
profilesByStatus[v] = 0;
|
|
511
|
+
for (const p of _smcpgovPsV2.values()) profilesByStatus[p.status]++;
|
|
512
|
+
const callsByStatus = {};
|
|
513
|
+
for (const v of Object.values(SMCPGOV_CALL_LIFECYCLE_V2))
|
|
514
|
+
callsByStatus[v] = 0;
|
|
515
|
+
for (const j of _smcpgovJsV2.values()) callsByStatus[j.status]++;
|
|
516
|
+
return {
|
|
517
|
+
totalSmcpgovProfilesV2: _smcpgovPsV2.size,
|
|
518
|
+
totalSmcpgovCallsV2: _smcpgovJsV2.size,
|
|
519
|
+
maxActiveSmcpgovProfilesPerOwner: _smcpgovMaxActive,
|
|
520
|
+
maxPendingSmcpgovCallsPerProfile: _smcpgovMaxPending,
|
|
521
|
+
smcpgovProfileIdleMs: _smcpgovIdleMs,
|
|
522
|
+
smcpgovCallStuckMs: _smcpgovStuckMs,
|
|
523
|
+
profilesByStatus,
|
|
524
|
+
callsByStatus,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
@@ -607,3 +607,333 @@ export function _resetStateSocialManagerV2() {
|
|
|
607
607
|
_relationshipIdleMsV2 = SOCIAL_DEFAULT_RELATIONSHIP_IDLE_MS;
|
|
608
608
|
_threadStuckMsV2 = SOCIAL_DEFAULT_THREAD_STUCK_MS;
|
|
609
609
|
}
|
|
610
|
+
|
|
611
|
+
// =====================================================================
|
|
612
|
+
// social-manager V2 governance overlay (iter22)
|
|
613
|
+
// =====================================================================
|
|
614
|
+
export const SMGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
615
|
+
PENDING: "pending",
|
|
616
|
+
ACTIVE: "active",
|
|
617
|
+
MUTED: "muted",
|
|
618
|
+
ARCHIVED: "archived",
|
|
619
|
+
});
|
|
620
|
+
export const SMGOV_POST_LIFECYCLE_V2 = Object.freeze({
|
|
621
|
+
QUEUED: "queued",
|
|
622
|
+
POSTING: "posting",
|
|
623
|
+
POSTED: "posted",
|
|
624
|
+
FAILED: "failed",
|
|
625
|
+
CANCELLED: "cancelled",
|
|
626
|
+
});
|
|
627
|
+
const _smgovPTrans = new Map([
|
|
628
|
+
[
|
|
629
|
+
SMGOV_PROFILE_MATURITY_V2.PENDING,
|
|
630
|
+
new Set([
|
|
631
|
+
SMGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
632
|
+
SMGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
633
|
+
]),
|
|
634
|
+
],
|
|
635
|
+
[
|
|
636
|
+
SMGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
637
|
+
new Set([
|
|
638
|
+
SMGOV_PROFILE_MATURITY_V2.MUTED,
|
|
639
|
+
SMGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
640
|
+
]),
|
|
641
|
+
],
|
|
642
|
+
[
|
|
643
|
+
SMGOV_PROFILE_MATURITY_V2.MUTED,
|
|
644
|
+
new Set([
|
|
645
|
+
SMGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
646
|
+
SMGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
647
|
+
]),
|
|
648
|
+
],
|
|
649
|
+
[SMGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
650
|
+
]);
|
|
651
|
+
const _smgovPTerminal = new Set([SMGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
652
|
+
const _smgovJTrans = new Map([
|
|
653
|
+
[
|
|
654
|
+
SMGOV_POST_LIFECYCLE_V2.QUEUED,
|
|
655
|
+
new Set([
|
|
656
|
+
SMGOV_POST_LIFECYCLE_V2.POSTING,
|
|
657
|
+
SMGOV_POST_LIFECYCLE_V2.CANCELLED,
|
|
658
|
+
]),
|
|
659
|
+
],
|
|
660
|
+
[
|
|
661
|
+
SMGOV_POST_LIFECYCLE_V2.POSTING,
|
|
662
|
+
new Set([
|
|
663
|
+
SMGOV_POST_LIFECYCLE_V2.POSTED,
|
|
664
|
+
SMGOV_POST_LIFECYCLE_V2.FAILED,
|
|
665
|
+
SMGOV_POST_LIFECYCLE_V2.CANCELLED,
|
|
666
|
+
]),
|
|
667
|
+
],
|
|
668
|
+
[SMGOV_POST_LIFECYCLE_V2.POSTED, new Set()],
|
|
669
|
+
[SMGOV_POST_LIFECYCLE_V2.FAILED, new Set()],
|
|
670
|
+
[SMGOV_POST_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
671
|
+
]);
|
|
672
|
+
const _smgovPsV2 = new Map();
|
|
673
|
+
const _smgovJsV2 = new Map();
|
|
674
|
+
let _smgovMaxActive = 10,
|
|
675
|
+
_smgovMaxPending = 30,
|
|
676
|
+
_smgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
677
|
+
_smgovStuckMs = 60 * 1000;
|
|
678
|
+
function _smgovPos(n, label) {
|
|
679
|
+
const v = Math.floor(Number(n));
|
|
680
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
681
|
+
throw new Error(`${label} must be positive integer`);
|
|
682
|
+
return v;
|
|
683
|
+
}
|
|
684
|
+
function _smgovCheckP(from, to) {
|
|
685
|
+
const a = _smgovPTrans.get(from);
|
|
686
|
+
if (!a || !a.has(to))
|
|
687
|
+
throw new Error(`invalid smgov profile transition ${from} → ${to}`);
|
|
688
|
+
}
|
|
689
|
+
function _smgovCheckJ(from, to) {
|
|
690
|
+
const a = _smgovJTrans.get(from);
|
|
691
|
+
if (!a || !a.has(to))
|
|
692
|
+
throw new Error(`invalid smgov post transition ${from} → ${to}`);
|
|
693
|
+
}
|
|
694
|
+
function _smgovCountActive(owner) {
|
|
695
|
+
let c = 0;
|
|
696
|
+
for (const p of _smgovPsV2.values())
|
|
697
|
+
if (p.owner === owner && p.status === SMGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
698
|
+
return c;
|
|
699
|
+
}
|
|
700
|
+
function _smgovCountPending(profileId) {
|
|
701
|
+
let c = 0;
|
|
702
|
+
for (const j of _smgovJsV2.values())
|
|
703
|
+
if (
|
|
704
|
+
j.profileId === profileId &&
|
|
705
|
+
(j.status === SMGOV_POST_LIFECYCLE_V2.QUEUED ||
|
|
706
|
+
j.status === SMGOV_POST_LIFECYCLE_V2.POSTING)
|
|
707
|
+
)
|
|
708
|
+
c++;
|
|
709
|
+
return c;
|
|
710
|
+
}
|
|
711
|
+
export function setMaxActiveSmgovProfilesPerOwnerV2(n) {
|
|
712
|
+
_smgovMaxActive = _smgovPos(n, "maxActiveSmgovProfilesPerOwner");
|
|
713
|
+
}
|
|
714
|
+
export function getMaxActiveSmgovProfilesPerOwnerV2() {
|
|
715
|
+
return _smgovMaxActive;
|
|
716
|
+
}
|
|
717
|
+
export function setMaxPendingSmgovPostsPerProfileV2(n) {
|
|
718
|
+
_smgovMaxPending = _smgovPos(n, "maxPendingSmgovPostsPerProfile");
|
|
719
|
+
}
|
|
720
|
+
export function getMaxPendingSmgovPostsPerProfileV2() {
|
|
721
|
+
return _smgovMaxPending;
|
|
722
|
+
}
|
|
723
|
+
export function setSmgovProfileIdleMsV2(n) {
|
|
724
|
+
_smgovIdleMs = _smgovPos(n, "smgovProfileIdleMs");
|
|
725
|
+
}
|
|
726
|
+
export function getSmgovProfileIdleMsV2() {
|
|
727
|
+
return _smgovIdleMs;
|
|
728
|
+
}
|
|
729
|
+
export function setSmgovPostStuckMsV2(n) {
|
|
730
|
+
_smgovStuckMs = _smgovPos(n, "smgovPostStuckMs");
|
|
731
|
+
}
|
|
732
|
+
export function getSmgovPostStuckMsV2() {
|
|
733
|
+
return _smgovStuckMs;
|
|
734
|
+
}
|
|
735
|
+
export function _resetStateSocialManagerGovV2() {
|
|
736
|
+
_smgovPsV2.clear();
|
|
737
|
+
_smgovJsV2.clear();
|
|
738
|
+
_smgovMaxActive = 10;
|
|
739
|
+
_smgovMaxPending = 30;
|
|
740
|
+
_smgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
741
|
+
_smgovStuckMs = 60 * 1000;
|
|
742
|
+
}
|
|
743
|
+
export function registerSmgovProfileV2({ id, owner, channel, metadata } = {}) {
|
|
744
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
745
|
+
if (_smgovPsV2.has(id)) throw new Error(`smgov profile ${id} already exists`);
|
|
746
|
+
const now = Date.now();
|
|
747
|
+
const p = {
|
|
748
|
+
id,
|
|
749
|
+
owner,
|
|
750
|
+
channel: channel || "timeline",
|
|
751
|
+
status: SMGOV_PROFILE_MATURITY_V2.PENDING,
|
|
752
|
+
createdAt: now,
|
|
753
|
+
updatedAt: now,
|
|
754
|
+
lastTouchedAt: now,
|
|
755
|
+
activatedAt: null,
|
|
756
|
+
archivedAt: null,
|
|
757
|
+
metadata: { ...(metadata || {}) },
|
|
758
|
+
};
|
|
759
|
+
_smgovPsV2.set(id, p);
|
|
760
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
761
|
+
}
|
|
762
|
+
export function activateSmgovProfileV2(id) {
|
|
763
|
+
const p = _smgovPsV2.get(id);
|
|
764
|
+
if (!p) throw new Error(`smgov profile ${id} not found`);
|
|
765
|
+
const isInitial = p.status === SMGOV_PROFILE_MATURITY_V2.PENDING;
|
|
766
|
+
_smgovCheckP(p.status, SMGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
767
|
+
if (isInitial && _smgovCountActive(p.owner) >= _smgovMaxActive)
|
|
768
|
+
throw new Error(`max active smgov profiles for owner ${p.owner} reached`);
|
|
769
|
+
const now = Date.now();
|
|
770
|
+
p.status = SMGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
771
|
+
p.updatedAt = now;
|
|
772
|
+
p.lastTouchedAt = now;
|
|
773
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
774
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
775
|
+
}
|
|
776
|
+
export function muteSmgovProfileV2(id) {
|
|
777
|
+
const p = _smgovPsV2.get(id);
|
|
778
|
+
if (!p) throw new Error(`smgov profile ${id} not found`);
|
|
779
|
+
_smgovCheckP(p.status, SMGOV_PROFILE_MATURITY_V2.MUTED);
|
|
780
|
+
p.status = SMGOV_PROFILE_MATURITY_V2.MUTED;
|
|
781
|
+
p.updatedAt = Date.now();
|
|
782
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
783
|
+
}
|
|
784
|
+
export function archiveSmgovProfileV2(id) {
|
|
785
|
+
const p = _smgovPsV2.get(id);
|
|
786
|
+
if (!p) throw new Error(`smgov profile ${id} not found`);
|
|
787
|
+
_smgovCheckP(p.status, SMGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
788
|
+
const now = Date.now();
|
|
789
|
+
p.status = SMGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
790
|
+
p.updatedAt = now;
|
|
791
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
792
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
793
|
+
}
|
|
794
|
+
export function touchSmgovProfileV2(id) {
|
|
795
|
+
const p = _smgovPsV2.get(id);
|
|
796
|
+
if (!p) throw new Error(`smgov profile ${id} not found`);
|
|
797
|
+
if (_smgovPTerminal.has(p.status))
|
|
798
|
+
throw new Error(`cannot touch terminal smgov profile ${id}`);
|
|
799
|
+
const now = Date.now();
|
|
800
|
+
p.lastTouchedAt = now;
|
|
801
|
+
p.updatedAt = now;
|
|
802
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
803
|
+
}
|
|
804
|
+
export function getSmgovProfileV2(id) {
|
|
805
|
+
const p = _smgovPsV2.get(id);
|
|
806
|
+
if (!p) return null;
|
|
807
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
808
|
+
}
|
|
809
|
+
export function listSmgovProfilesV2() {
|
|
810
|
+
return [..._smgovPsV2.values()].map((p) => ({
|
|
811
|
+
...p,
|
|
812
|
+
metadata: { ...p.metadata },
|
|
813
|
+
}));
|
|
814
|
+
}
|
|
815
|
+
export function createSmgovPostV2({ id, profileId, author, metadata } = {}) {
|
|
816
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
817
|
+
if (_smgovJsV2.has(id)) throw new Error(`smgov post ${id} already exists`);
|
|
818
|
+
if (!_smgovPsV2.has(profileId))
|
|
819
|
+
throw new Error(`smgov profile ${profileId} not found`);
|
|
820
|
+
if (_smgovCountPending(profileId) >= _smgovMaxPending)
|
|
821
|
+
throw new Error(`max pending smgov posts for profile ${profileId} reached`);
|
|
822
|
+
const now = Date.now();
|
|
823
|
+
const j = {
|
|
824
|
+
id,
|
|
825
|
+
profileId,
|
|
826
|
+
author: author || "",
|
|
827
|
+
status: SMGOV_POST_LIFECYCLE_V2.QUEUED,
|
|
828
|
+
createdAt: now,
|
|
829
|
+
updatedAt: now,
|
|
830
|
+
startedAt: null,
|
|
831
|
+
settledAt: null,
|
|
832
|
+
metadata: { ...(metadata || {}) },
|
|
833
|
+
};
|
|
834
|
+
_smgovJsV2.set(id, j);
|
|
835
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
836
|
+
}
|
|
837
|
+
export function postingSmgovPostV2(id) {
|
|
838
|
+
const j = _smgovJsV2.get(id);
|
|
839
|
+
if (!j) throw new Error(`smgov post ${id} not found`);
|
|
840
|
+
_smgovCheckJ(j.status, SMGOV_POST_LIFECYCLE_V2.POSTING);
|
|
841
|
+
const now = Date.now();
|
|
842
|
+
j.status = SMGOV_POST_LIFECYCLE_V2.POSTING;
|
|
843
|
+
j.updatedAt = now;
|
|
844
|
+
if (!j.startedAt) j.startedAt = now;
|
|
845
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
846
|
+
}
|
|
847
|
+
export function completePostSmgovV2(id) {
|
|
848
|
+
const j = _smgovJsV2.get(id);
|
|
849
|
+
if (!j) throw new Error(`smgov post ${id} not found`);
|
|
850
|
+
_smgovCheckJ(j.status, SMGOV_POST_LIFECYCLE_V2.POSTED);
|
|
851
|
+
const now = Date.now();
|
|
852
|
+
j.status = SMGOV_POST_LIFECYCLE_V2.POSTED;
|
|
853
|
+
j.updatedAt = now;
|
|
854
|
+
if (!j.settledAt) j.settledAt = now;
|
|
855
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
856
|
+
}
|
|
857
|
+
export function failSmgovPostV2(id, reason) {
|
|
858
|
+
const j = _smgovJsV2.get(id);
|
|
859
|
+
if (!j) throw new Error(`smgov post ${id} not found`);
|
|
860
|
+
_smgovCheckJ(j.status, SMGOV_POST_LIFECYCLE_V2.FAILED);
|
|
861
|
+
const now = Date.now();
|
|
862
|
+
j.status = SMGOV_POST_LIFECYCLE_V2.FAILED;
|
|
863
|
+
j.updatedAt = now;
|
|
864
|
+
if (!j.settledAt) j.settledAt = now;
|
|
865
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
866
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
867
|
+
}
|
|
868
|
+
export function cancelSmgovPostV2(id, reason) {
|
|
869
|
+
const j = _smgovJsV2.get(id);
|
|
870
|
+
if (!j) throw new Error(`smgov post ${id} not found`);
|
|
871
|
+
_smgovCheckJ(j.status, SMGOV_POST_LIFECYCLE_V2.CANCELLED);
|
|
872
|
+
const now = Date.now();
|
|
873
|
+
j.status = SMGOV_POST_LIFECYCLE_V2.CANCELLED;
|
|
874
|
+
j.updatedAt = now;
|
|
875
|
+
if (!j.settledAt) j.settledAt = now;
|
|
876
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
877
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
878
|
+
}
|
|
879
|
+
export function getSmgovPostV2(id) {
|
|
880
|
+
const j = _smgovJsV2.get(id);
|
|
881
|
+
if (!j) return null;
|
|
882
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
883
|
+
}
|
|
884
|
+
export function listSmgovPostsV2() {
|
|
885
|
+
return [..._smgovJsV2.values()].map((j) => ({
|
|
886
|
+
...j,
|
|
887
|
+
metadata: { ...j.metadata },
|
|
888
|
+
}));
|
|
889
|
+
}
|
|
890
|
+
export function autoMuteIdleSmgovProfilesV2({ now } = {}) {
|
|
891
|
+
const t = now ?? Date.now();
|
|
892
|
+
const flipped = [];
|
|
893
|
+
for (const p of _smgovPsV2.values())
|
|
894
|
+
if (
|
|
895
|
+
p.status === SMGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
896
|
+
t - p.lastTouchedAt >= _smgovIdleMs
|
|
897
|
+
) {
|
|
898
|
+
p.status = SMGOV_PROFILE_MATURITY_V2.MUTED;
|
|
899
|
+
p.updatedAt = t;
|
|
900
|
+
flipped.push(p.id);
|
|
901
|
+
}
|
|
902
|
+
return { flipped, count: flipped.length };
|
|
903
|
+
}
|
|
904
|
+
export function autoFailStuckSmgovPostsV2({ now } = {}) {
|
|
905
|
+
const t = now ?? Date.now();
|
|
906
|
+
const flipped = [];
|
|
907
|
+
for (const j of _smgovJsV2.values())
|
|
908
|
+
if (
|
|
909
|
+
j.status === SMGOV_POST_LIFECYCLE_V2.POSTING &&
|
|
910
|
+
j.startedAt != null &&
|
|
911
|
+
t - j.startedAt >= _smgovStuckMs
|
|
912
|
+
) {
|
|
913
|
+
j.status = SMGOV_POST_LIFECYCLE_V2.FAILED;
|
|
914
|
+
j.updatedAt = t;
|
|
915
|
+
if (!j.settledAt) j.settledAt = t;
|
|
916
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
917
|
+
flipped.push(j.id);
|
|
918
|
+
}
|
|
919
|
+
return { flipped, count: flipped.length };
|
|
920
|
+
}
|
|
921
|
+
export function getSocialManagerGovStatsV2() {
|
|
922
|
+
const profilesByStatus = {};
|
|
923
|
+
for (const v of Object.values(SMGOV_PROFILE_MATURITY_V2))
|
|
924
|
+
profilesByStatus[v] = 0;
|
|
925
|
+
for (const p of _smgovPsV2.values()) profilesByStatus[p.status]++;
|
|
926
|
+
const postsByStatus = {};
|
|
927
|
+
for (const v of Object.values(SMGOV_POST_LIFECYCLE_V2)) postsByStatus[v] = 0;
|
|
928
|
+
for (const j of _smgovJsV2.values()) postsByStatus[j.status]++;
|
|
929
|
+
return {
|
|
930
|
+
totalSmgovProfilesV2: _smgovPsV2.size,
|
|
931
|
+
totalSmgovPostsV2: _smgovJsV2.size,
|
|
932
|
+
maxActiveSmgovProfilesPerOwner: _smgovMaxActive,
|
|
933
|
+
maxPendingSmgovPostsPerProfile: _smgovMaxPending,
|
|
934
|
+
smgovProfileIdleMs: _smgovIdleMs,
|
|
935
|
+
smgovPostStuckMs: _smgovStuckMs,
|
|
936
|
+
profilesByStatus,
|
|
937
|
+
postsByStatus,
|
|
938
|
+
};
|
|
939
|
+
}
|