cognitivebc 0.1.0 → 0.2.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/LICENSE +70 -0
- package/README.md +98 -4
- package/SECURITY.md +29 -0
- package/TERMS_OF_SERVICE.md +55 -0
- package/bin/cbc-cloud-bootstrap.js +108 -0
- package/bin/cbc-seed-projects.js +29 -0
- package/bin/cbc-server.js +45 -0
- package/bin/cognitivebc.js +251 -0
- package/docs/ACCESS_CONTROL.md +111 -0
- package/docs/ARTIFACT_AUDIT.md +36 -0
- package/docs/CONNECT_CLIENTS.md +116 -0
- package/docs/DEPLOY_AZURE.md +136 -0
- package/docs/INGESTION.md +29 -0
- package/docs/OPERATIONS.md +85 -0
- package/docs/PROJECT_IDENTITY.md +35 -0
- package/docs/RESOLVER.md +86 -0
- package/docs/SDK.md +96 -0
- package/docs/STORAGE.md +63 -0
- package/docs/TECHNICAL_SPECIFICATION.md +365 -0
- package/docs/TELEMETRY.md +119 -0
- package/index.js +27 -2
- package/package.json +45 -5
- package/packages/cbc-compiler/index.js +357 -0
- package/packages/cbc-compiler/sanitizer.js +43 -0
- package/packages/cbc-identity/index.js +92 -0
- package/packages/cbc-mcp/http-backend.js +138 -0
- package/packages/cbc-mcp/http-route.js +64 -0
- package/packages/cbc-mcp/index.js +50 -0
- package/packages/cbc-mcp/tools.js +122 -0
- package/packages/cbc-resolver/catalog-linker.js +215 -0
- package/packages/cbc-resolver/graph-builder.js +533 -0
- package/packages/cbc-resolver/index.js +548 -0
- package/packages/cbc-resolver/obsidian-bridge.js +564 -0
- package/packages/cbc-schema/index.js +194 -0
- package/packages/cbc-sdk-js/client.js +162 -0
- package/services/cbc-api/access-policy.js +130 -0
- package/services/cbc-api/artifact-audit.js +167 -0
- package/services/cbc-api/cloud.js +56 -0
- package/services/cbc-api/context-service.js +48 -0
- package/services/cbc-api/ingestion-service.js +234 -0
- package/services/cbc-api/pg-store.js +172 -0
- package/services/cbc-api/project-registry.js +322 -0
- package/services/cbc-api/public/app.html +123 -0
- package/services/cbc-api/public/graph.html +1168 -0
- package/services/cbc-api/public/graph2.html +455 -0
- package/services/cbc-api/public/graph3.html +503 -0
- package/services/cbc-api/public/index.html +78 -0
- package/services/cbc-api/public/vendor/cbc-app.js +209 -0
- package/services/cbc-api/public/vendor/cbc-auth.js +49 -0
- package/services/cbc-api/public/vendor/cbc-site.css +101 -0
- package/services/cbc-api/public/vendor/cose-base.js +3214 -0
- package/services/cbc-api/public/vendor/cytoscape-dagre.js +397 -0
- package/services/cbc-api/public/vendor/cytoscape-fcose.js +1549 -0
- package/services/cbc-api/public/vendor/cytoscape.min.js +32 -0
- package/services/cbc-api/public/vendor/dagre.min.js +3809 -0
- package/services/cbc-api/public/vendor/graphology-library.min.js +2 -0
- package/services/cbc-api/public/vendor/graphology.umd.min.js +2 -0
- package/services/cbc-api/public/vendor/layout-base.js +5230 -0
- package/services/cbc-api/public/vendor/pf-graph.css +86 -0
- package/services/cbc-api/public/vendor/pf-telemetry.js +176 -0
- package/services/cbc-api/public/vendor/sigma.min.js +1351 -0
- package/services/cbc-api/runtime-info.js +39 -0
- package/services/cbc-api/server.js +642 -0
- package/services/cbc-api/store-loader.js +269 -0
- package/services/cbc-api/telemetry.js +148 -0
- package/services/cbc-api/token-service.js +61 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* Tokens do PerformacIA Design System (modo escuro do site: --site-dark-*) */
|
|
2
|
+
:root {
|
|
3
|
+
--bg:#060606; --surface:#101013; --surface-2:#0C0C0E; --line:#26262A; --hair:rgba(255,255,255,.08);
|
|
4
|
+
--txt:#F5F5F5; --txt-2:#A3A3A3; --txt-3:#8A8A91;
|
|
5
|
+
--brand:#A78BFA; --brand-solid:#7C3AED; --eco:#34D399; --alert:#FB923C;
|
|
6
|
+
--font-display:'Space Grotesk',sans-serif; --font-body:'IBM Plex Sans',sans-serif;
|
|
7
|
+
--font-mono:'IBM Plex Mono',ui-monospace,monospace;
|
|
8
|
+
--texture: repeating-linear-gradient(60deg, rgba(255,255,255,.032) 0 1px, transparent 1px 26px),
|
|
9
|
+
repeating-linear-gradient(-60deg, rgba(255,255,255,.032) 0 1px, transparent 1px 26px),
|
|
10
|
+
repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, transparent 1px 26px);
|
|
11
|
+
}
|
|
12
|
+
* { box-sizing:border-box; }
|
|
13
|
+
html,body { margin:0; height:100%; background:var(--bg); color:var(--txt); font:14px/1.45 var(--font-body); -webkit-font-smoothing:antialiased; }
|
|
14
|
+
header { min-height:56px; display:flex; flex-wrap:nowrap; align-items:center; gap:8px; padding:0 18px; border-bottom:1px solid var(--line); background:var(--bg); overflow-x:auto; }
|
|
15
|
+
header > * { flex:none; }
|
|
16
|
+
.brand { display:flex; align-items:center; gap:10px; margin-right:10px; }
|
|
17
|
+
.brand svg { width:20px; height:22px; }
|
|
18
|
+
header h1 { font:600 15px/1 var(--font-display); margin:0; letter-spacing:-.01em; white-space:nowrap; }
|
|
19
|
+
header h1 span { color:var(--txt-3); font-weight:500; }
|
|
20
|
+
#stats, header a { white-space:nowrap; }
|
|
21
|
+
header .sp { flex:1 1 auto; }
|
|
22
|
+
select,input,button { background:var(--surface); color:var(--txt); border:1px solid var(--line); border-radius:999px; padding:6px 13px; font:500 13px var(--font-body); outline:none; }
|
|
23
|
+
select { padding-right:28px; appearance:none; background-image:linear-gradient(45deg,transparent 50%,var(--txt-3) 50%),linear-gradient(135deg,var(--txt-3) 50%,transparent 50%);
|
|
24
|
+
background-position:calc(100% - 15px) 52%, calc(100% - 11px) 52%; background-size:4px 4px; background-repeat:no-repeat; }
|
|
25
|
+
input::placeholder { color:var(--txt-3); }
|
|
26
|
+
button { cursor:pointer; } button:hover,select:hover,input:focus { border-color:#3a3a40; }
|
|
27
|
+
button.on { border-color:rgba(167,139,250,.6); color:var(--brand); background:rgba(124,58,237,.10); }
|
|
28
|
+
.seg { display:inline-flex; border:1px solid var(--line); border-radius:999px; padding:2px; background:var(--surface); }
|
|
29
|
+
.seg button { border:0; background:transparent; padding:5px 12px; } .seg button.on { background:rgba(124,58,237,.16); }
|
|
30
|
+
main { position:absolute; top:56px; bottom:0; left:0; right:0; display:flex; }
|
|
31
|
+
#stage { flex:1; position:relative; background:
|
|
32
|
+
radial-gradient(circle at 84% 12%, rgba(124,58,237,.16), transparent 28%),
|
|
33
|
+
radial-gradient(circle at 12% 92%, rgba(16,185,129,.07), transparent 26%), var(--texture), var(--bg); }
|
|
34
|
+
#cy { position:absolute; inset:0; }
|
|
35
|
+
aside { width:360px; border-left:1px solid var(--line); background:var(--surface-2); overflow:auto; padding:20px; }
|
|
36
|
+
.eyebrow { font:600 11px/1 var(--font-mono); text-transform:uppercase; letter-spacing:.14em; color:var(--txt-3); margin:22px 0 12px; }
|
|
37
|
+
.eyebrow:first-child { margin-top:0; }
|
|
38
|
+
.legend { display:grid; grid-template-columns:1fr 1fr; gap:8px 10px; }
|
|
39
|
+
.legend label { display:flex; align-items:center; gap:9px; cursor:pointer; color:var(--txt-2); user-select:none; font-size:13px; }
|
|
40
|
+
.legend label.off { opacity:.35; }
|
|
41
|
+
.legend input { display:none; }
|
|
42
|
+
.legend .n { margin-left:auto; font:500 11px var(--font-mono); color:var(--txt-3); }
|
|
43
|
+
.glyph { width:10px; height:10px; flex:none; display:inline-block; }
|
|
44
|
+
.glyph.diamond { transform:rotate(45deg); width:8px; height:8px; margin:0 1px; }
|
|
45
|
+
.glyph.outline { background:transparent !important; border:1.5px solid currentColor; }
|
|
46
|
+
.glyph.round { border-radius:50%; } .glyph.square { border-radius:2px; } .glyph.hex { clip-path:polygon(25% 5%,75% 5%,100% 50%,75% 95%,25% 95%,0 50%); }
|
|
47
|
+
.card { background:var(--surface); border:1px solid var(--line); border-radius:20px; padding:16px 18px; }
|
|
48
|
+
.title { display:flex; align-items:center; gap:10px; font:600 17px/1.2 var(--font-display); letter-spacing:-.01em; margin-bottom:8px; }
|
|
49
|
+
.muted { color:var(--txt-3); } .kv { margin:6px 0; color:var(--txt-2); font-size:13px; } .kv b { color:var(--txt-3); font:600 11px var(--font-mono); text-transform:uppercase; letter-spacing:.08em; margin-right:6px; }
|
|
50
|
+
.chip { display:inline-block; padding:3px 10px; border-radius:999px; font:500 12px var(--font-body); border:1px solid var(--hair); color:var(--txt-2); background:rgba(255,255,255,.03); margin:0 4px 4px 0; }
|
|
51
|
+
.chip.brand { color:var(--brand); border-color:rgba(167,139,250,.35); background:rgba(124,58,237,.08); }
|
|
52
|
+
.rule { position:relative; color:var(--txt); background:var(--bg); border:1px solid var(--line); border-radius:16px; padding:14px 16px; margin:12px 0; white-space:pre-wrap; font-size:13.5px; }
|
|
53
|
+
/* cantoneiras: moldura de canto da identidade, num único módulo por tela */
|
|
54
|
+
.rule::before,.rule::after { content:''; position:absolute; width:10px; height:10px; border:1.5px solid rgba(167,139,250,.55); }
|
|
55
|
+
.rule::before { top:-1px; left:-1px; border-right:0; border-bottom:0; border-radius:6px 0 0 0; }
|
|
56
|
+
.rule::after { bottom:-1px; right:-1px; border-left:0; border-top:0; border-radius:0 0 6px 0; }
|
|
57
|
+
#stats { color:var(--txt-3); font:500 12px var(--font-mono); }
|
|
58
|
+
#nb div { padding:6px 0; border-bottom:1px solid var(--hair); color:var(--txt-3); font-size:13px; }
|
|
59
|
+
#nb .rel { font:500 11px var(--font-mono); text-transform:uppercase; letter-spacing:.06em; margin-right:8px; }
|
|
60
|
+
#nb a { color:var(--txt); cursor:pointer; text-decoration:none; } #nb a:hover { color:var(--brand); }
|
|
61
|
+
header a { color:var(--txt-3); text-decoration:none; font-size:13px; } header a:hover { color:var(--txt); }
|
|
62
|
+
|
|
63
|
+
/* ---- Telemetria (compartilhado por /graph2 e /graph3) ---- */
|
|
64
|
+
.usage { background:var(--surface); border:1px solid var(--line); border-radius:16px; padding:12px 14px; margin-bottom:6px; }
|
|
65
|
+
.usage .big { font:500 13px var(--font-body); color:var(--txt-2); } .usage .big b { font:600 22px/1 var(--font-display); color:var(--txt); margin-right:4px; }
|
|
66
|
+
.usage.none { color:var(--txt-3); font-size:13px; border-style:dashed; }
|
|
67
|
+
.spark { display:block; margin:10px 0 6px; }
|
|
68
|
+
.ev { display:flex; gap:10px; padding:7px 0; border-bottom:1px solid var(--hair); font-size:13px; color:var(--txt-2); }
|
|
69
|
+
.ev b { color:var(--txt); font-weight:500; } .ev .muted { font-size:11.5px; }
|
|
70
|
+
.dotlive { width:7px; height:7px; border-radius:50%; margin-top:6px; flex:none; background:#5A5A62; }
|
|
71
|
+
.dotlive.resolve { background:var(--eco); } .dotlive.event { background:var(--brand); }
|
|
72
|
+
.timebar { position:absolute; left:16px; right:70px; bottom:14px; z-index:2; display:flex; align-items:center; gap:12px;
|
|
73
|
+
background:rgba(16,16,19,.85); border:1px solid var(--line); border-radius:999px; padding:6px 14px; backdrop-filter:blur(8px); }
|
|
74
|
+
.timebar input[type=range] { flex:1; accent-color:#A78BFA; padding:0; border:0; background:transparent; }
|
|
75
|
+
.timebar .when { font:500 11px var(--font-mono); color:var(--txt-2); min-width:110px; text-align:right; }
|
|
76
|
+
.timebar button { padding:3px 10px; font-size:12px; }
|
|
77
|
+
.livebadge { display:inline-flex; align-items:center; gap:6px; }
|
|
78
|
+
.livebadge::before { content:''; width:7px; height:7px; border-radius:50%; background:#5A5A62; }
|
|
79
|
+
button.on.livebadge::before { background:var(--eco); box-shadow:0 0 0 0 rgba(52,211,153,.6); animation:pfpulse 1.6s infinite; }
|
|
80
|
+
@keyframes pfpulse { 0%{box-shadow:0 0 0 0 rgba(52,211,153,.55)} 70%{box-shadow:0 0 0 7px rgba(52,211,153,0)} 100%{box-shadow:0 0 0 0 rgba(52,211,153,0)} }
|
|
81
|
+
#telsum { color:var(--txt-3); font:500 11px var(--font-mono); margin-top:-4px; margin-bottom:10px; }
|
|
82
|
+
.sizectl { display:flex; align-items:center; gap:10px; }
|
|
83
|
+
.sizectl select { flex:none; }
|
|
84
|
+
.sizectl input[type=range] { flex:1; accent-color:#A78BFA; padding:0; border:0; background:transparent; }
|
|
85
|
+
.sizectl .n { font:500 11px var(--font-mono); color:var(--txt-2); min-width:30px; text-align:right; }
|
|
86
|
+
.sizehint { color:var(--txt-3); font-size:12px; margin-top:8px; }
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/* Telemetria do CognitiveBC para os grafos (/graph2 Cytoscape e /graph3 Sigma.js).
|
|
2
|
+
Só lógica e HTML do painel; cada grafo decide como desenhar tamanho, esmaecimento e pulso. */
|
|
3
|
+
(function () {
|
|
4
|
+
const RULE_TYPES = new Set(['constraint', 'heuristic', 'principle', 'experience']);
|
|
5
|
+
const T = { data: null, live: false, since: null, timer: null, listeners: [] };
|
|
6
|
+
|
|
7
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
|
8
|
+
const key = (id) => String(id || '').replace(/^[a-z_]+:/, '');
|
|
9
|
+
|
|
10
|
+
T.load = async function () {
|
|
11
|
+
T.data = await (await fetch('/api/v1/telemetry?days=30')).json();
|
|
12
|
+
T.since = T.data.generated_at;
|
|
13
|
+
return T.data;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Métrica de uso de um nó do grafo (regra, papel, job ou tenant), ou null quando o tipo não é medido. */
|
|
17
|
+
T.metric = function (node) {
|
|
18
|
+
const d = T.data; if (!d || !node) return null;
|
|
19
|
+
const k = key(node.id);
|
|
20
|
+
if (RULE_TYPES.has(node.type)) return d.rules[k] || d.rules[node.name] || { count: 0, empty: true };
|
|
21
|
+
if (node.type === 'role') return d.roles[k] || { count: 0, empty: true };
|
|
22
|
+
if (node.type === 'production_job') return d.jobs[k] || d.jobs[node.name] || null;
|
|
23
|
+
if (node.type === 'tenant') return d.tenants[k] || null;
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
T.isRule = (node) => RULE_TYPES.has(node.type);
|
|
27
|
+
|
|
28
|
+
/** Escala 1..2.4 pelo log do uso, comparado ao maior uso do mesmo tipo. */
|
|
29
|
+
T.scale = function (node, all) {
|
|
30
|
+
const m = T.metric(node); if (!m) return 1;
|
|
31
|
+
if (!m.count) return T.isRule(node) ? .8 : 1;
|
|
32
|
+
const max = Math.max(1, ...all.filter(n => n.type === node.type).map(n => (T.metric(n) || {}).count || 0));
|
|
33
|
+
return 1 + 1.4 * Math.log1p(m.count) / Math.log1p(max);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
T.ago = function (ts) {
|
|
37
|
+
if (!ts) return 'nunca';
|
|
38
|
+
const s = Math.max(0, (Date.now() - Date.parse(ts)) / 1000);
|
|
39
|
+
if (s < 60) return 'agora'; if (s < 3600) return `há ${Math.round(s / 60)} min`;
|
|
40
|
+
if (s < 86400) return `há ${Math.round(s / 3600)} h`; return `há ${Math.round(s / 86400)} d`;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
T.spark = function (daily, w = 290, h = 38) {
|
|
44
|
+
if (!daily || !daily.length) return '';
|
|
45
|
+
const max = Math.max(1, ...daily), step = w / (daily.length - 1 || 1);
|
|
46
|
+
const pts = daily.map((v, i) => `${(i * step).toFixed(1)},${(h - 3 - (v / max) * (h - 8)).toFixed(1)}`);
|
|
47
|
+
return `<svg class="spark" viewBox="0 0 ${w} ${h}" width="100%" height="${h}" preserveAspectRatio="none">
|
|
48
|
+
<polyline points="0,${h} ${pts.join(' ')} ${w},${h}" fill="rgba(124,58,237,.14)" stroke="none"/>
|
|
49
|
+
<polyline points="${pts.join(' ')}" fill="none" stroke="#A78BFA" stroke-width="1.5" vector-effect="non-scaling-stroke"/></svg>`;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const top = (o, n = 4) => Object.entries(o || {}).sort((a, b) => b[1] - a[1]).slice(0, n);
|
|
53
|
+
|
|
54
|
+
/** Bloco "Uso" do painel de detalhes. */
|
|
55
|
+
T.panel = function (node) {
|
|
56
|
+
const m = T.metric(node);
|
|
57
|
+
if (!m) return '';
|
|
58
|
+
const isRule = T.isRule(node);
|
|
59
|
+
const label = isRule ? 'aplicações' : node.type === 'role' ? 'pedidos e eventos' : 'eventos';
|
|
60
|
+
if (!m.count) {
|
|
61
|
+
return `<div class="eyebrow">Uso · 30 dias</div><div class="usage none">${isRule
|
|
62
|
+
? 'Nunca aplicada a nenhum agente desde que a telemetria começou. Candidata a revisão ou a papel sem agente real.'
|
|
63
|
+
: 'Sem uso registrado.'}</div>`;
|
|
64
|
+
}
|
|
65
|
+
const who = top(m.agents).length ? top(m.agents) : top(m.roles);
|
|
66
|
+
return `<div class="eyebrow">Uso · 30 dias</div>
|
|
67
|
+
<div class="usage"><div class="big"><b>${m.count}</b> ${label}</div><div class="muted">último ${T.ago(m.last)}${m.tokens ? ` · ${m.tokens.toLocaleString('pt-BR')} tokens` : ''}</div>
|
|
68
|
+
${T.spark(m.daily)}
|
|
69
|
+
${who.length ? `<div class="kv"><b>${top(m.agents).length ? 'Agentes' : 'Papéis'}</b> ${who.map(([k, v]) => `<span class="chip">${esc(k)} · ${v}</span>`).join('')}</div>` : ''}</div>`;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** Lista "Atividade" com os eventos mais recentes. */
|
|
73
|
+
T.feed = function (events, n = 8) {
|
|
74
|
+
if (!events || !events.length) return '<span class="muted">Sem atividade registrada.</span>';
|
|
75
|
+
return events.slice(0, n).map(e => {
|
|
76
|
+
const what = e.kind === 'resolve'
|
|
77
|
+
? `<b>${esc(e.agent || e.role)}</b> recebeu ${e.ids.length} regra${e.ids.length === 1 ? '' : 's'}`
|
|
78
|
+
: `<b>${esc(e.role || '?')}</b> ${esc(String(e.type || 'evento').replace(/^runtime-|^message-/, ''))}`;
|
|
79
|
+
return `<div class="ev"><span class="dotlive ${e.kind}"></span><div>${what}<div class="muted">${esc(e.tenant || '')}${e.session ? ' · ' + esc(e.session.replace(/^synapse-/, '')) : ''} · ${T.ago(e.ts)}</div></div></div>`;
|
|
80
|
+
}).join('');
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
T.summary = function () {
|
|
84
|
+
const d = T.data; if (!d) return '';
|
|
85
|
+
return `${d.totals.resolves} pedidos · ${d.totals.events} eventos · ${d.totals.rules_used} regras usadas`;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** Ao vivo: consulta eventos novos a cada 4 s e entrega ids de nós afetados. */
|
|
89
|
+
T.setLive = function (on, onEvents) {
|
|
90
|
+
T.live = on;
|
|
91
|
+
clearInterval(T.timer);
|
|
92
|
+
if (!on) return;
|
|
93
|
+
T.timer = setInterval(async () => {
|
|
94
|
+
try {
|
|
95
|
+
const r = await (await fetch('/api/v1/telemetry/events?since=' + encodeURIComponent(T.since))).json();
|
|
96
|
+
if (!r.events.length) return;
|
|
97
|
+
T.since = r.events[0].ts;
|
|
98
|
+
await T.load();
|
|
99
|
+
const ids = new Set();
|
|
100
|
+
for (const e of r.events) {
|
|
101
|
+
(e.ids || []).forEach(i => ids.add(i));
|
|
102
|
+
if (e.role) ids.add('role:' + e.role);
|
|
103
|
+
if (e.session) ids.add('job:' + e.session);
|
|
104
|
+
}
|
|
105
|
+
onEvents(r.events, ids);
|
|
106
|
+
} catch (_) { /* servidor reiniciando */ }
|
|
107
|
+
}, 4000);
|
|
108
|
+
};
|
|
109
|
+
/** Nós do grafo que correspondem aos ids vindos da telemetria. */
|
|
110
|
+
T.matchNodes = function (nodes, ids) {
|
|
111
|
+
return nodes.filter(n => ids.has(n.id) || ids.has(key(n.id)) || ids.has(n.name)).map(n => n.id);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Linha do tempo: limites e rótulo. */
|
|
115
|
+
T.timeBounds = function (graph) {
|
|
116
|
+
const ts = graph.nodes.map(n => Date.parse(n.created_at)).filter(Number.isFinite);
|
|
117
|
+
return ts.length ? { min: Math.min(...ts), max: Math.max(Date.now(), ...ts) } : null;
|
|
118
|
+
};
|
|
119
|
+
T.fmt = (t) => new Date(t).toLocaleString('pt-BR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' });
|
|
120
|
+
|
|
121
|
+
/* ---- Tamanho dos nós (seletor dinâmico, compartilhado) ---- */
|
|
122
|
+
T.SIZE_MODES = [
|
|
123
|
+
['uso', 'Uso', 'Aplicações (regras), pedidos e eventos (papéis) e eventos (jobs) nos últimos 30 dias.'],
|
|
124
|
+
['conexoes', 'Conexões', 'Número de vínculos do nó no grafo visível.'],
|
|
125
|
+
['tokens', 'Tokens', 'Tokens consumidos (papéis e jobs com telemetria).'],
|
|
126
|
+
['recencia', 'Recência', 'Maior quanto mais recente o último uso.'],
|
|
127
|
+
['fixo', 'Fixo', 'Tamanho padrão de cada tipo, sem métrica.'],
|
|
128
|
+
];
|
|
129
|
+
const qs = new URLSearchParams(location.search);
|
|
130
|
+
T.size = {
|
|
131
|
+
mode: T.SIZE_MODES.some(m => m[0] === qs.get('size')) ? qs.get('size') : (qs.get('usage') === '0' ? 'fixo' : 'uso'),
|
|
132
|
+
scale: Math.min(2.5, Math.max(.5, parseFloat(qs.get('scale')) || 1)),
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** Fator de tamanho por nó (Map id -> fator), conforme o modo e a escala escolhidos. */
|
|
136
|
+
T.sizeMap = function (nodes, links) {
|
|
137
|
+
const mode = T.size.mode, deg = {};
|
|
138
|
+
if (mode === 'conexoes') for (const l of links || []) { deg[l.source] = (deg[l.source] || 0) + 1; deg[l.target] = (deg[l.target] || 0) + 1; }
|
|
139
|
+
const val = (n) => {
|
|
140
|
+
const m = T.metric(n);
|
|
141
|
+
if (mode === 'uso') return m ? m.count : null;
|
|
142
|
+
if (mode === 'conexoes') return deg[n.id] || 0;
|
|
143
|
+
if (mode === 'tokens') return m ? (m.tokens || 0) : null;
|
|
144
|
+
if (mode === 'recencia') return m ? (m.last ? Math.max(0, 30 - (Date.now() - Date.parse(m.last)) / 86400000) : 0) : null;
|
|
145
|
+
return null;
|
|
146
|
+
};
|
|
147
|
+
const vals = new Map(nodes.map(n => [n.id, val(n)]));
|
|
148
|
+
const grp = (n) => (mode === 'conexoes' ? '*' : n.type); // conexões: comparação global; demais: dentro do tipo
|
|
149
|
+
const max = {};
|
|
150
|
+
for (const n of nodes) { const v = vals.get(n.id); if (v != null) max[grp(n)] = Math.max(max[grp(n)] || 0, v); }
|
|
151
|
+
const out = new Map();
|
|
152
|
+
for (const n of nodes) {
|
|
153
|
+
const v = vals.get(n.id), mx = max[grp(n)] || 0;
|
|
154
|
+
let f = 1;
|
|
155
|
+
if (v != null && mx > 0) f = mode === 'recencia' ? .8 + 1.6 * (v / 30) : 1 + 1.4 * Math.log1p(v) / Math.log1p(mx);
|
|
156
|
+
if (mode === 'uso' && v === 0 && T.isRule(n)) f = .8;
|
|
157
|
+
out.set(n.id, f * T.size.scale);
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
};
|
|
161
|
+
T.isUnused = (n) => { if (T.size.mode !== 'uso') return false; const m = T.metric(n); return !!m && T.isRule(n) && !m.count; };
|
|
162
|
+
T.writeParams = (p) => { if (T.size.mode !== 'uso') p.set('size', T.size.mode); if (T.size.scale !== 1) p.set('scale', T.size.scale.toFixed(1)); };
|
|
163
|
+
|
|
164
|
+
T.mountSizeControls = function (el, onChange) {
|
|
165
|
+
const hint = () => (T.SIZE_MODES.find(m => m[0] === T.size.mode) || [])[2] || '';
|
|
166
|
+
el.innerHTML = `<div class="sizectl">
|
|
167
|
+
<select id="sizeBy" aria-label="Métrica do tamanho">${T.SIZE_MODES.map(([k, l]) => `<option value="${k}" ${k === T.size.mode ? 'selected' : ''}>${l}</option>`).join('')}</select>
|
|
168
|
+
<input id="sizeScale" type="range" min="0.5" max="2.5" step="0.1" value="${T.size.scale}" aria-label="Escala">
|
|
169
|
+
<span class="n" id="sizeVal">${T.size.scale.toFixed(1)}×</span></div>
|
|
170
|
+
<div class="sizehint" id="sizeHint">${esc(hint())}</div>`;
|
|
171
|
+
el.querySelector('#sizeBy').onchange = (e) => { T.size.mode = e.target.value; el.querySelector('#sizeHint').textContent = hint(); onChange(); };
|
|
172
|
+
el.querySelector('#sizeScale').oninput = (e) => { T.size.scale = parseFloat(e.target.value); el.querySelector('#sizeVal').textContent = T.size.scale.toFixed(1) + '×'; onChange(); };
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
window.PFTel = T;
|
|
176
|
+
})();
|