agentglow 0.1.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.
@@ -0,0 +1,848 @@
1
+ var hs = Object.defineProperty;
2
+ var fs = (l, t, n) => t in l ? hs(l, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : l[t] = n;
3
+ var y = (l, t, n) => fs(l, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsx as G, jsxs as ft, Fragment as _t } from "react/jsx-runtime";
5
+ import { OrbitControls as ds } from "@react-three/drei";
6
+ import { Canvas as us, useThree as ps, useFrame as bt } from "@react-three/fiber";
7
+ import { EffectComposer as ms, Bloom as gs, Vignette as Ms, Noise as ys } from "@react-three/postprocessing";
8
+ import { useState as jt, useMemo as ns, useEffect as is, useRef as tt } from "react";
9
+ import * as x from "three";
10
+ import { K as bs, h as Zt, w as _, b as Jt, R as xs, c as Qt, p as As, e as ws, S as V, l as dt, d as Lt, i as Rs, T as rs, C as Ss, f as zs, H as Gs, L as ut, t as Cs, g as vs, u as Is } from "./ClusterBall-CPsd6JvJ.js";
11
+ import { r as Fs, j as zt, a as ts, i as Bs } from "./spread-CWdeDFd9.js";
12
+ var os;
13
+ const pt = typeof window < "u" && !!((os = window.matchMedia) != null && os.call(window, "(prefers-reduced-motion: reduce)").matches), rt = pt ? 0.3 : 1, X = pt ? 9e3 : 24e3, at = pt ? 3500 : 8e3, k = 6, Z = pt ? 450 : 1100, Ot = 9e3, q = 48, At = 31, ct = 4.6, st = 28, Tt = 64, wt = 18, kt = 16, ot = 8, N = Math.PI * 2, Ps = 200, H = [
14
+ [-14.5, 2.5],
15
+ [14.5, 2.5],
16
+ [0, -13.5],
17
+ [-12, -12],
18
+ [12, -12],
19
+ [0, 14]
20
+ ], as = (l) => zt(l, 71) * 0.9, Dt = new Float32Array(6), Et = (l, t = Dt[l]) => Math.atan2(-H[l][1], -H[l][0]) + Math.PI / 3 + t;
21
+ function yt(l, t, n, e = Dt[l]) {
22
+ const s = Et(l, e) + t * N / 3;
23
+ return n.set(H[l][0] + Math.cos(s) * ct, 0.35, H[l][1] + Math.sin(s) * ct);
24
+ }
25
+ const Os = [-150, -30, -100, 150, 30, -62, -128, 90].map((l) => l * Math.PI / 180);
26
+ function Gt(l, t) {
27
+ const n = Os[l % ot], e = 27 + (l >= ot ? 3 : 0);
28
+ return t.set(Math.cos(n) * e, 3.2 + l % 2 * 1.2, Math.sin(n) * e);
29
+ }
30
+ const Mt = Object.fromEntries(Object.entries(rs).map(([l, t]) => [l, new x.Color(t)])), ss = { planner: 0, researcher: 1, graph_scout: 1, records_scout: 1, data_scout: 1, writer: 2 }, Rt = Bs, Ts = () => ({ used: !1, id: "", inst: null, seen: 0, x: 0, y: 0, z: 0, r: 1, g: 1, b: 1, omega: 0, bright: 0, swirl: 0, rscale: 1, tiltA: 0, tiltB: 0, count: 0, want: 0, rank: 0, dTh: 0, rad: 0, released: !1, p: 0, e: 0, waitMcp: 0 }), et = (l) => {
31
+ const t = Math.sin(l * 127.1 + 311.7) * 43758.5453;
32
+ return t - Math.floor(t);
33
+ };
34
+ function lt(l) {
35
+ const t = new x.BufferGeometry();
36
+ return t.setAttribute("position", new x.BufferAttribute(new Float32Array(l * 3), 3).setUsage(x.DynamicDrawUsage)), t.setAttribute("acol", new x.BufferAttribute(new Float32Array(l * 3), 3).setUsage(x.DynamicDrawUsage)), t.setAttribute("size", new x.BufferAttribute(new Float32Array(l), 1).setUsage(x.DynamicDrawUsage)), t;
37
+ }
38
+ const U = (l, t) => l.getAttribute(t).array, ht = (l) => {
39
+ l.getAttribute("position").needsUpdate = !0, l.getAttribute("acol").needsUpdate = !0, l.getAttribute("size").needsUpdate = !0;
40
+ };
41
+ function ks() {
42
+ return new x.ShaderMaterial({
43
+ uniforms: { uScale: { value: 300 }, uPR: { value: 1 } },
44
+ vertexShader: (
45
+ /* glsl */
46
+ `
47
+ attribute vec3 acol;
48
+ attribute float size;
49
+ uniform float uScale;
50
+ uniform float uPR;
51
+ varying vec3 vC;
52
+ void main() {
53
+ vec4 mv = modelViewMatrix * vec4(position, 1.0);
54
+ gl_Position = projectionMatrix * mv;
55
+ gl_PointSize = min(96.0, size * uPR * uScale / max(0.5, -mv.z));
56
+ vC = acol;
57
+ if (size <= 0.0) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
58
+ }`
59
+ ),
60
+ fragmentShader: (
61
+ /* glsl */
62
+ `
63
+ varying vec3 vC;
64
+ void main() {
65
+ vec2 c = gl_PointCoord - 0.5;
66
+ float d = dot(c, c) * 4.0;
67
+ if (d > 1.0) discard;
68
+ float a = exp(-d * 3.2) - 0.04;
69
+ gl_FragColor = vec4(vC * max(a, 0.0), 1.0);
70
+ }`
71
+ ),
72
+ transparent: !0,
73
+ depthWrite: !1,
74
+ blending: x.AdditiveBlending
75
+ });
76
+ }
77
+ const R = new x.Vector3(), W = new x.Vector3(), T = new x.Vector3(), S = new x.Color(), J = new x.Color(), Q = new x.Object3D(), K = new x.Color(1, 1, 1), es = new x.Color("#fbbf24"), Ls = new x.Color("#ef4444"), Es = new x.Color("#ef4444");
78
+ class _s {
79
+ constructor(t) {
80
+ y(this, "galaxy");
81
+ y(this, "material", ks());
82
+ y(this, "frame", 0);
83
+ y(this, "selectedId", null);
84
+ // ---- field
85
+ y(this, "fieldGeo", lt(X));
86
+ y(this, "fP", U(this.fieldGeo, "position"));
87
+ y(this, "fC", U(this.fieldGeo, "acol"));
88
+ y(this, "fS", U(this.fieldGeo, "size"));
89
+ y(this, "fYb", new Float32Array(X));
90
+ y(this, "fIvx", new Float32Array(X));
91
+ y(this, "fIvz", new Float32Array(X));
92
+ y(this, "fHeat", new Float32Array(X));
93
+ y(this, "fT", new Float32Array(X * 3));
94
+ y(this, "fOwner", new Int16Array(X).fill(-1));
95
+ y(this, "fAng", new Float32Array(X));
96
+ y(this, "fOrb", new Float32Array(X));
97
+ y(this, "fRnd", new Float32Array(X));
98
+ // ---- slots (agent instances)
99
+ y(this, "slots", Array.from({ length: q }, Ts));
100
+ y(this, "idToSlot", /* @__PURE__ */ new Map());
101
+ y(this, "pendingByInst", /* @__PURE__ */ new Map());
102
+ // ---- runs
103
+ y(this, "runRef", new Array(k).fill(null));
104
+ y(this, "rAlpha", new Float32Array(k));
105
+ y(this, "rCol", Array.from({ length: k }, () => new x.Color()));
106
+ y(this, "rColStr", new Array(k).fill(""));
107
+ y(this, "runGeo", lt(k * Z));
108
+ y(this, "rTh", new Float32Array(k * Z));
109
+ y(this, "rSp", new Float32Array(k * Z));
110
+ y(this, "rRr", new Float32Array(k * Z));
111
+ y(this, "rY", new Float32Array(k * Z));
112
+ // ---- nebula (FalkorDB)
113
+ y(this, "nebGeo", lt(at));
114
+ y(this, "anchorGeo");
115
+ y(this, "nA", new Uint16Array(at));
116
+ y(this, "nO", new Float32Array(at * 3));
117
+ y(this, "nSpin", new Float32Array(at));
118
+ y(this, "nB", new Float32Array(at));
119
+ y(this, "aLocal");
120
+ y(this, "aCol");
121
+ y(this, "aNamed");
122
+ y(this, "burst");
123
+ y(this, "burstW");
124
+ y(this, "flareCol");
125
+ y(this, "nameIdx", /* @__PURE__ */ new Map());
126
+ y(this, "nebAngle", 0.4);
127
+ y(this, "nAnchors", 1);
128
+ y(this, "edgeGeo", new x.BufferGeometry());
129
+ y(this, "edgeA", new Uint16Array(0));
130
+ y(this, "lastFlareId", 0);
131
+ y(this, "lastFlare", null);
132
+ // ---- streams + lines
133
+ y(this, "streamGeo", lt(Ot));
134
+ y(this, "beamGeo");
135
+ y(this, "glowGeo", lt(q + k * 3 + ot));
136
+ // ---- meshes
137
+ y(this, "cores");
138
+ y(this, "hits");
139
+ y(this, "attractors");
140
+ y(this, "stepRings");
141
+ y(this, "rings");
142
+ y(this, "pulsars");
143
+ y(this, "pulsarBeams");
144
+ y(this, "selRing");
145
+ y(this, "ringStart", new Float32Array(st).fill(-1e9));
146
+ y(this, "ringDur", new Float32Array(st).fill(1));
147
+ y(this, "ringMax", new Float32Array(st));
148
+ y(this, "ringPos", new Float32Array(st * 3));
149
+ y(this, "ringCol", new Float32Array(st * 3));
150
+ y(this, "ringNext", 0);
151
+ y(this, "mcpSpin", new Float32Array(ot));
152
+ // ------------------------------------------------------------------ frame
153
+ /** LOD size multiplier for eddies, sampled once per frame */
154
+ y(this, "lodK", 1);
155
+ // active runs / swirls packed for the hot loop
156
+ y(this, "aX", new Float32Array(k));
157
+ y(this, "aZ", new Float32Array(k));
158
+ y(this, "aA", new Float32Array(k));
159
+ y(this, "aR", new Float32Array(k * 3));
160
+ y(this, "sX", new Float32Array(q));
161
+ y(this, "sZ", new Float32Array(q));
162
+ y(this, "sS", new Float32Array(q));
163
+ var g, w, d;
164
+ this.galaxy = t;
165
+ const n = Math.max(1, Math.min(Ps, t.nodes.length));
166
+ this.nAnchors = n, t.nodes.slice(0, n).forEach((o, f) => this.nameIdx.set(o.name.toLowerCase(), f));
167
+ for (let o = 0; o < X; o++) {
168
+ const f = Math.sqrt(Math.random()) * At, a = Math.random() * N;
169
+ this.fP[o * 3] = Math.cos(a) * f, this.fP[o * 3 + 2] = Math.sin(a) * f, this.fYb[o] = (Math.random() - 0.5) * (0.6 + f * 0.05), this.fP[o * 3 + 1] = this.fYb[o], this.fRnd[o] = Math.random(), this.fOrb[o] = 0.16 + 1.35 * Math.pow(Math.random(), 1.5), this.fAng[o] = Math.random() * N;
170
+ }
171
+ for (let o = 0; o < k * Z; o++) {
172
+ this.rTh[o] = Math.random() * N, this.rSp[o] = 0.2 + Math.random() * 0.14;
173
+ const f = (Math.random() + Math.random() + Math.random() - 1.5) * 0.55;
174
+ this.rRr[o] = f, this.rY[o] = (Math.random() - 0.5) * 0.35;
175
+ }
176
+ this.aLocal = new Float32Array(n * 3), this.aCol = new Float32Array(n * 3), this.aNamed = new Uint8Array(n), this.burst = new Float32Array(n), this.burstW = new Float32Array(n), this.flareCol = new Float32Array(n * 3);
177
+ for (let o = 0; o < n; o++) {
178
+ const f = o / n, a = 0.5 + 4.6 * Math.sqrt(f) + (Math.random() - 0.5) * 0.45, M = o % 3 / 3 * N + a * 1.15 + (Math.random() - 0.5) * 0.5;
179
+ this.aLocal[o * 3] = Math.cos(M) * a, this.aLocal[o * 3 + 1] = (Math.random() - 0.5) * 0.7 * (1.3 - f) + 0.4, this.aLocal[o * 3 + 2] = Math.sin(M) * a, S.set(bs[((g = t.nodes[o]) == null ? void 0 : g.kind) ?? ""] ?? "#94a3b8"), this.aCol[o * 3] = S.r, this.aCol[o * 3 + 1] = S.g, this.aCol[o * 3 + 2] = S.b, this.aNamed[o] = o < 22 ? 1 : 0;
180
+ }
181
+ for (let o = 0; o < at; o++) {
182
+ const f = Math.random() < 0.2 ? Math.floor(Math.random() * Math.min(22, n)) : Math.floor(Math.random() * n);
183
+ this.nA[o] = f;
184
+ const a = 0.18 + 0.55 * Math.pow(Math.random(), 3), M = Math.random() * N, O = a * Math.sqrt(-2 * Math.log(1 - Math.random() * 0.98));
185
+ this.nO[o * 3] = Math.cos(M) * O, this.nO[o * 3 + 1] = (Math.random() - 0.5) * a * 0.8, this.nO[o * 3 + 2] = Math.sin(M) * O, this.nSpin[o] = (0.15 + Math.random() * 0.5) * (Math.random() < 0.5 ? 1 : 0.6), this.nB[o] = 0.5 + Math.random() * 0.7;
186
+ }
187
+ this.anchorGeo = lt(n);
188
+ const e = [], s = /* @__PURE__ */ new Set(), r = (o, f) => {
189
+ if (o === f) return;
190
+ const a = o < f ? `${o}-${f}` : `${f}-${o}`;
191
+ s.has(a) || (s.add(a), e.push(o, f));
192
+ };
193
+ for (const o of t.links) {
194
+ const f = this.nameIdx.get(((w = t.nodes.find((M) => M.id === o.source)) == null ? void 0 : w.name.toLowerCase()) ?? ""), a = this.nameIdx.get(((d = t.nodes.find((M) => M.id === o.target)) == null ? void 0 : d.name.toLowerCase()) ?? "");
195
+ if (f !== void 0 && a !== void 0) {
196
+ const M = this.aLocal[f * 3] - this.aLocal[a * 3], O = this.aLocal[f * 3 + 2] - this.aLocal[a * 3 + 2];
197
+ M * M + O * O < 9 && r(f, a);
198
+ }
199
+ }
200
+ for (let o = 0; o < n; o++) {
201
+ let f = -1, a = 1e9, M = -1, O = 1e9;
202
+ for (let z = 0; z < n; z++) {
203
+ if (z === o) continue;
204
+ const I = this.aLocal[o * 3] - this.aLocal[z * 3], L = this.aLocal[o * 3 + 1] - this.aLocal[z * 3 + 1], B = this.aLocal[o * 3 + 2] - this.aLocal[z * 3 + 2], j = I * I + L * L + B * B;
205
+ j < a ? (M = f, O = a, f = z, a = j) : j < O && (M = z, O = j);
206
+ }
207
+ f >= 0 && r(o, f), M >= 0 && o % 2 === 0 && r(o, M);
208
+ }
209
+ this.edgeA = Uint16Array.from(e);
210
+ const m = new Float32Array(e.length * 3), b = Math.cos(this.nebAngle), c = Math.sin(this.nebAngle);
211
+ e.forEach((o, f) => {
212
+ const a = this.aLocal[o * 3], M = this.aLocal[o * 3 + 2];
213
+ m[f * 3] = a * b - M * c, m[f * 3 + 1] = this.aLocal[o * 3 + 1], m[f * 3 + 2] = a * c + M * b;
214
+ }), this.edgeGeo.setAttribute("position", new x.BufferAttribute(m, 3)), this.edgeGeo.setAttribute("color", new x.BufferAttribute(new Float32Array(e.length * 3), 3).setUsage(x.DynamicDrawUsage));
215
+ const i = Tt + kt * wt;
216
+ this.beamGeo = new x.BufferGeometry(), this.beamGeo.setAttribute("position", new x.BufferAttribute(new Float32Array(i * 6), 3).setUsage(x.DynamicDrawUsage)), this.beamGeo.setAttribute("color", new x.BufferAttribute(new Float32Array(i * 6), 3).setUsage(x.DynamicDrawUsage));
217
+ const u = new x.Sphere(new x.Vector3(), 400), v = new x.MeshBasicMaterial({ toneMapped: !1 });
218
+ this.cores = new x.InstancedMesh(new x.IcosahedronGeometry(0.26, 3), v, q), this.hits = new x.InstancedMesh(new x.SphereGeometry(0.95, 10, 8), new x.MeshBasicMaterial({ transparent: !0, opacity: 0, depthWrite: !1, colorWrite: !1 }), q), this.attractors = new x.InstancedMesh(new x.IcosahedronGeometry(0.3, 3), new x.MeshBasicMaterial({ toneMapped: !1 }), k * 3);
219
+ const F = new x.RingGeometry(0.9, 1, 96);
220
+ F.rotateX(-Math.PI / 2);
221
+ const C = () => new x.MeshBasicMaterial({ toneMapped: !1, transparent: !0, blending: x.AdditiveBlending, depthWrite: !1, side: x.DoubleSide });
222
+ this.stepRings = new x.InstancedMesh(new x.RingGeometry(0.93, 1, 6, 1).rotateX(-Math.PI / 2), C(), k * 3), this.rings = new x.InstancedMesh(F, C(), st), this.pulsars = new x.InstancedMesh(new x.OctahedronGeometry(0.42, 0), new x.MeshBasicMaterial({ toneMapped: !1 }), ot);
223
+ const P = new x.ConeGeometry(0.12, 3.2, 8, 1, !0);
224
+ P.translate(0, 1.6, 0);
225
+ const p = P.clone().rotateX(Math.PI), A = new x.BufferGeometry();
226
+ ((o, f) => {
227
+ const a = o.getAttribute("position").array, M = f.getAttribute("position").array, O = o.getIndex().array, z = f.getIndex().array, I = new Float32Array(a.length + M.length);
228
+ I.set(a), I.set(M, a.length);
229
+ const L = [...O, ...Array.from(z, (B) => B + a.length / 3)];
230
+ A.setAttribute("position", new x.BufferAttribute(I, 3)), A.setIndex(L);
231
+ })(P, p), this.pulsarBeams = new x.InstancedMesh(A, C(), ot);
232
+ for (const o of [this.cores, this.hits, this.attractors, this.stepRings, this.rings, this.pulsars, this.pulsarBeams]) {
233
+ o.boundingSphere = u, o.frustumCulled = !1, o.instanceMatrix.setUsage(x.DynamicDrawUsage), o.setColorAt(0, S.setRGB(0, 0, 0));
234
+ for (let f = 0; f < o.count; f++)
235
+ Q.position.set(0, -999, 0), Q.scale.setScalar(1e-4), Q.updateMatrix(), o.setMatrixAt(f, Q.matrix), o.setColorAt(f, S.setRGB(0, 0, 0));
236
+ }
237
+ this.selRing = new x.Mesh(new x.RingGeometry(1.25, 1.33, 64).rotateX(-Math.PI / 2), C()), this.selRing.visible = !1;
238
+ }
239
+ dispose() {
240
+ for (const t of [this.edgeGeo, this.fieldGeo, this.runGeo, this.nebGeo, this.anchorGeo, this.streamGeo, this.beamGeo, this.glowGeo]) t.dispose();
241
+ for (const t of [this.cores, this.hits, this.attractors, this.stepRings, this.rings, this.pulsars, this.pulsarBeams])
242
+ t.geometry.dispose(), t.material.dispose(), t.dispose();
243
+ this.material.dispose();
244
+ }
245
+ // ------------------------------------------------------------------ helpers
246
+ anchorIdx(t) {
247
+ const n = t.toLowerCase();
248
+ let e = this.nameIdx.get(n);
249
+ if (e === void 0) {
250
+ let s = 7;
251
+ for (let r = 0; r < n.length; r++) s = s * 31 + n.charCodeAt(r) >>> 0;
252
+ e = s % this.nAnchors, this.nameIdx.set(n, e);
253
+ }
254
+ return e;
255
+ }
256
+ anchorWorld(t, n) {
257
+ const e = Math.cos(this.nebAngle), s = Math.sin(this.nebAngle), r = this.aLocal[t * 3], m = this.aLocal[t * 3 + 2];
258
+ return n.set(r * e - m * s, this.aLocal[t * 3 + 1], r * s + m * e);
259
+ }
260
+ slotOf(t) {
261
+ const n = this.idToSlot.get(t);
262
+ return n === void 0 ? null : this.slots[n];
263
+ }
264
+ emitRing(t, n, e, s, r, m, b, c = 1) {
265
+ const i = this.ringNext++ % st;
266
+ this.ringStart[i] = b, this.ringDur[i] = m, this.ringMax[i] = r, this.ringPos.set([t, n, e], i * 3), this.ringCol.set([s.r * c, s.g * c, s.b * c], i * 3);
267
+ }
268
+ alloc(t, n) {
269
+ const e = this.slots.findIndex((b) => !b.used);
270
+ if (e < 0) return -1;
271
+ const s = this.slots[e], r = Mt[t.type];
272
+ if (Object.assign(s, { used: !0, id: t.id, inst: t, count: 0, released: !1, r: r.r, g: r.g, b: r.b, omega: 2, bright: 0.6, swirl: 0, p: 0, e: 0 }), s.tiltA = (et(e + n) - 0.5) * 0.7, s.tiltB = (et(e * 3.1 + n) - 0.5) * 0.7, s.rscale = Rt(t.type) ? 0.72 : 1, s.want = Math.round((Rt(t.type) ? 380 : 620) * (pt ? 0.5 : 1)), s.rank = Fs(t), Rt(t.type)) {
273
+ const b = Zt(t.run, 72) < 0.5 ? -1 : 1;
274
+ s.dTh = zt(t.run, 73) * 0.5 + b * ts(s.rank) * 0.62, s.rad = 4.4 * (0.88 + 0.26 * Zt(t.id, 74));
275
+ } else
276
+ s.dTh = ts(s.rank) * 0.5 + zt(t.id, 75) * 0.16, s.rad = ct - 1.9 + zt(t.id, 76) * 0.7;
277
+ const m = t.parent ? this.slotOf(t.parent) : null;
278
+ if (m)
279
+ s.x = m.x, s.y = m.y, s.z = m.z;
280
+ else {
281
+ const b = _.runs.get(t.run);
282
+ yt(((b == null ? void 0 : b.slot) ?? 0) % k, ss[t.type], R), s.x = R.x, s.y = R.y, s.z = R.z;
283
+ }
284
+ if (this.idToSlot.set(t.id, e), this.emitRing(s.x, s.y, s.z, r, 2.4, 0.9, n, 2.2), m) {
285
+ const b = this.idToSlot.get(t.parent);
286
+ let c = Math.floor(m.count * 0.28);
287
+ for (let i = 0; i < X && c > 0; i++)
288
+ this.fOwner[i] === b && i & 1 && (this.fOwner[i] = e, m.count--, s.count++, c--);
289
+ }
290
+ return e;
291
+ }
292
+ release(t, n) {
293
+ const e = this.slots[t], s = this.fP;
294
+ for (let r = 0; r < X; r++) {
295
+ if (this.fOwner[r] !== t) continue;
296
+ this.fOwner[r] = -1;
297
+ const m = s[r * 3] - e.x, b = s[r * 3 + 2] - e.z, c = Math.sqrt(m * m + b * b) + 1e-3, i = (2.4 + this.fRnd[r] * 3.6) * (pt ? 0.5 : 1);
298
+ this.fIvx[r] = m / c * i - b / c * e.omega * 0.5, this.fIvz[r] = b / c * i + m / c * e.omega * 0.5, this.fHeat[r] = 1, this.fT[r * 3] = e.r, this.fT[r * 3 + 1] = e.g, this.fT[r * 3 + 2] = e.b;
299
+ }
300
+ e.count = 0, S.setRGB(e.r, e.g, e.b).lerp(K, 0.5), this.emitRing(e.x, e.y, e.z, S, 3.2, 1.1, n, 2.6);
301
+ }
302
+ update(t, n, e) {
303
+ const s = Math.min(0.05, t);
304
+ this.lodK = Jt(), this.frame++, this.syncRuns(n, s), this.syncSlots(n, s, e), this.recruit(n), this.updateField(s, e), this.updateFlares(n), this.updateNebula(e), this.updateRunCurrents(n, e), this.updateStreams(n, e), this.updateMeshes(n, e, s);
305
+ }
306
+ syncRuns(t, n) {
307
+ this.runRef.fill(null);
308
+ for (const e of _.runs.values()) {
309
+ const s = e.slot % k, r = this.runRef[s], m = !dt.grouped || Lt(e.id), b = !!r && (!dt.grouped || Lt(r.id));
310
+ (!r || m && !b || m === b && e.startedAt > r.startedAt) && (this.runRef[s] = e);
311
+ }
312
+ for (let e = 0; e < k; e++) {
313
+ const s = this.runRef[e];
314
+ Dt[e] = s ? as(s.id) : 0;
315
+ let r = 0;
316
+ s && (r = Math.min(1, (t - s.startedAt) / 1800), s.endedAt && (r *= Math.max(0, 1 - (t - s.endedAt - (xs - 3e3)) / 3e3)), s.color !== this.rColStr[e] && (this.rColStr[e] = s.color, this.rCol[e].set(s.color))), this.rAlpha[e] += (r - this.rAlpha[e]) * Math.min(1, n * 3);
317
+ }
318
+ }
319
+ syncSlots(t, n, e) {
320
+ const s = this.frame;
321
+ for (const b of _.instances.values()) {
322
+ if (dt.grouped && !Rs(b)) continue;
323
+ let c = this.idToSlot.get(b.id);
324
+ c === void 0 && (c = this.alloc(b, t)), !(c < 0) && (this.slots[c].seen = s, this.slots[c].inst = b);
325
+ }
326
+ this.pendingByInst.clear();
327
+ for (const b of _.mcpPending.values()) this.pendingByInst.set(b.instance, Math.max(this.pendingByInst.get(b.instance) ?? 0, Qt(b, t)));
328
+ const r = 1 - Math.exp(-n * 2.2), m = 1 - Math.exp(-n * 4);
329
+ for (let b = 0; b < q; b++) {
330
+ const c = this.slots[b];
331
+ if (!c.used) continue;
332
+ const i = c.inst;
333
+ if (c.seen !== s) {
334
+ c.count > 0 && this.release(b, t), c.used = !1, c.inst = null, this.idToSlot.delete(c.id);
335
+ continue;
336
+ }
337
+ const u = _.runs.get(i.run), v = ((u == null ? void 0 : u.slot) ?? 0) % k, F = ss[i.type], C = Et(v) + F * N / 3, P = Rt(i.type), p = P ? ct - 1.9 : c.rad, A = P ? C : C + c.dTh;
338
+ let h = H[v][0] + Math.cos(A) * p, g = H[v][1] + Math.sin(A) * p;
339
+ if (P) {
340
+ const M = C + c.dTh;
341
+ h += Math.cos(M) * c.rad, g += Math.sin(M) * c.rad;
342
+ }
343
+ const w = 0.9 + Math.sin(e * 0.9 + b) * 0.18;
344
+ i.exitAt || (c.x += (h - c.x) * r, c.y += (w - c.y) * r, c.z += (g - c.z) * r), c.p = As(i, t), c.e = ws(i, t), c.waitMcp = this.pendingByInst.get(i.id) ?? -1;
345
+ const d = i.status === "thinking", o = i.status === "waiting";
346
+ let f = d ? 3.6 : o ? 0.7 : 2.2, a = d ? 1 : o ? 0.3 : 0.7;
347
+ c.waitMcp >= 0 && (f = 1, a = 0.45 + 0.3 * (0.5 + 0.5 * Math.sin(e * 3.2))), i.exitAt && (f = 0, a = 0), c.omega += (f * (1 + c.e * 0.7) * rt - c.omega) * m, c.bright += (a + c.e * 1.2 - c.bright) * m, c.swirl = i.exitAt ? 0 : (d ? 1.6 : 0.6) * c.p * rt, i.exitAt && !c.released && (c.released = !0, this.release(b, t));
348
+ }
349
+ }
350
+ recruit(t) {
351
+ const n = this.fP;
352
+ for (let e = 0; e < q; e++) {
353
+ const s = this.slots[e];
354
+ if (!s.used || !s.inst || s.inst.exitAt) continue;
355
+ const r = (t - s.inst.bornAt) / 1e3, m = s.want * Math.min(1, r / 1.6);
356
+ for (let b = 0; b < 140 && s.count < m; b++) {
357
+ const c = Math.random() * X | 0;
358
+ if (this.fOwner[c] !== -1) continue;
359
+ const i = n[c * 3] - s.x, u = n[c * 3 + 2] - s.z;
360
+ i * i + u * u > 120 || (this.fOwner[c] = e, this.fAng[c] = Math.atan2(u, i), s.count++);
361
+ }
362
+ }
363
+ }
364
+ updateField(t, n) {
365
+ const e = this.fP, s = this.fC, r = this.fS, m = this.fOwner, b = this.slots, c = this.fRnd, i = t * rt, u = n * rt, v = 1 - Math.exp(-t * 2.8), F = Math.exp(-t * 0.5), C = Math.exp(-t * 1.3), P = 0.23 * u, p = 0.17 * u, A = 0.11 * u;
366
+ let h = 0;
367
+ for (let d = 0; d < k; d++)
368
+ this.rAlpha[d] < 0.01 || (this.aX[h] = H[d][0], this.aZ[h] = H[d][1], this.aA[h] = this.rAlpha[d], this.aR[h * 3] = this.rCol[d].r, this.aR[h * 3 + 1] = this.rCol[d].g, this.aR[h * 3 + 2] = this.rCol[d].b, h++);
369
+ let g = 0;
370
+ for (const d of b)
371
+ !d.used || d.swirl <= 0.01 || (this.sX[g] = d.x, this.sZ[g] = d.z, this.sS[g] = d.swirl, g++);
372
+ const w = At * At;
373
+ for (let d = 0; d < X; d++) {
374
+ const o = d * 3;
375
+ let f = e[o], a = e[o + 1], M = e[o + 2];
376
+ const O = m[d];
377
+ if (O >= 0) {
378
+ const z = b[O], I = this.fOrb[d] * z.rscale * (0.35 + 0.65 * z.p) * this.lodK, L = this.fAng[d] += z.omega * t / (0.3 + I), B = Math.cos(L), j = Math.sin(L), E = z.x + B * I, $ = z.z + j * I, Ct = z.y + (j * z.tiltA + B * z.tiltB) * I + (c[d] - 0.5) * 0.14;
379
+ f += (E - f) * v, a += (Ct - a) * v, M += ($ - M) * v;
380
+ const mt = z.bright * (1.5 - I * 0.55) * (0.6 + 0.4 * c[d]);
381
+ s[o] = z.r * mt + 0.05, s[o + 1] = z.g * mt + 0.05, s[o + 2] = z.b * mt + 0.05, r[d] = 0.5 + 0.35 * c[d];
382
+ } else {
383
+ const z = f * f + M * M, I = Math.sqrt(z) + 1e-4, L = I / 11, B = 1.25 * L / (1 + L * L);
384
+ let j = -M / I * B, E = f / I * B;
385
+ const $ = Math.sin(0.27 * f + P), Ct = Math.cos(0.27 * f + P), mt = Math.sin(0.31 * M - p), Ut = Math.cos(0.31 * M - p), Nt = 0.41 * M + 0.33 * f + A, cs = Math.sin(Nt), Wt = Math.cos(Nt);
386
+ j += ($ * -0.31 * mt + 0.7 * 0.41 * Wt) * 3, E -= (0.27 * Ct * Ut + 0.7 * 0.33 * Wt) * 3;
387
+ const $t = $ * Ut + 0.7 * cs + I * 0.09, vt = 0.5 + 0.5 * Math.sin($t * 5.5), Xt = vt * vt * vt;
388
+ let qt = 0, Ht = 0, Vt = 0;
389
+ for (let D = 0; D < h; D++) {
390
+ const Y = f - this.aX[D], nt = M - this.aZ[D], gt = Y * Y + nt * nt;
391
+ if (gt > 140) continue;
392
+ const it = Math.sqrt(gt) + 1e-4, Bt = it / ct, Yt = 2.6 * this.aA[D] * Bt * Math.exp(-Bt * Bt * 0.6);
393
+ j -= nt / it * Yt, E += Y / it * Yt;
394
+ const Kt = it - ct, Pt = Math.exp(-Kt * Kt * 0.55) * this.aA[D];
395
+ qt += this.aR[D * 3] * Pt, Ht += this.aR[D * 3 + 1] * Pt, Vt += this.aR[D * 3 + 2] * Pt;
396
+ }
397
+ for (let D = 0; D < g; D++) {
398
+ const Y = f - this.sX[D], nt = M - this.sZ[D], gt = Y * Y + nt * nt;
399
+ if (gt > 16) continue;
400
+ const it = this.sS[D] / (1 + gt * 0.9);
401
+ j -= nt * it, E += Y * it;
402
+ }
403
+ j += this.fIvx[d], E += this.fIvz[d], this.fIvx[d] *= C, this.fIvz[d] *= C, f += j * i, M += E * i, a += (this.fYb[d] - a) * t * 1.2;
404
+ const xt = this.fHeat[d] *= F, ls = j * j + E * E, It = (0.14 + Xt * 2.8) * (0.6 + Math.min(1.2, ls * 0.3)) * (0.45 + 0.75 * c[d]), Ft = 0.5 + 0.5 * Math.sin($t * 1.3 + 1);
405
+ if (s[o] = (0.05 + 0.05 * Ft) * It + qt * 0.42 + this.fT[o] * xt * 1.8, s[o + 1] = (0.08 + 0.03 * Ft) * It + Ht * 0.42 + this.fT[o + 1] * xt * 1.8, s[o + 2] = (0.2 - 0.04 * Ft) * It + Vt * 0.42 + this.fT[o + 2] * xt * 1.8, r[d] = 0.26 + 0.2 * c[d] + Xt * 0.12 + xt * 0.35, z > w) {
406
+ const D = Math.sqrt(Math.random()) * At * 0.97, Y = Math.random() * N;
407
+ f = Math.cos(Y) * D, M = Math.sin(Y) * D, this.fHeat[d] = 0, this.fIvx[d] = this.fIvz[d] = 0;
408
+ }
409
+ }
410
+ e[o] = f, e[o + 1] = a, e[o + 2] = M;
411
+ }
412
+ ht(this.fieldGeo);
413
+ }
414
+ updateFlares(t) {
415
+ this.burst.fill(0), this.burstW.fill(0);
416
+ for (const n of _.flares) {
417
+ const e = this.anchorIdx(n.node), s = (t - n.start) / 1e3, r = (1 - Math.exp(-s * 9)) * Math.exp(-s * 1.3);
418
+ if (n.id > this.lastFlareId) {
419
+ if (this.lastFlareId = n.id, this.anchorWorld(e, R), n.op === "write")
420
+ this.emitRing(R.x, R.y, R.z, K, 4.2, 1.7, t, 2.4), this.emitRing(R.x, R.y, R.z, K, 2.2, 1, t, 1.6);
421
+ else {
422
+ const m = _.instances.get(n.instance);
423
+ this.emitRing(R.x, R.y, R.z, m ? Mt[m.type] : K, 1.1, 0.7, t, 1.6);
424
+ }
425
+ this.lastFlare = { name: n.node, op: n.op, at: t, idx: e };
426
+ }
427
+ if (r > this.burst[e]) {
428
+ this.burst[e] = r;
429
+ const m = _.instances.get(n.instance), b = n.op === "write" ? K : m ? Mt[m.type] : K;
430
+ this.flareCol[e * 3] = b.r, this.flareCol[e * 3 + 1] = b.g, this.flareCol[e * 3 + 2] = b.b, n.op === "write" && (this.burstW[e] = 1);
431
+ }
432
+ }
433
+ }
434
+ updateNebula(t) {
435
+ const n = U(this.nebGeo, "position"), e = U(this.nebGeo, "acol"), s = U(this.nebGeo, "size"), r = Math.cos(this.nebAngle), m = Math.sin(this.nebAngle), b = t * rt, c = this.aLocal, i = this.aCol, u = this.flareCol;
436
+ for (let h = 0; h < at; h++) {
437
+ const g = this.nA[h], w = this.burst[g], d = b * this.nSpin[h], o = Math.cos(d), f = Math.sin(d), a = this.nO[h * 3], M = this.nO[h * 3 + 2], O = 1 + w * (2.2 + this.burstW[g] * 4.5), z = c[g * 3] + (a * o - M * f) * O, I = c[g * 3 + 2] + (a * f + M * o) * O, L = c[g * 3 + 1] + this.nO[h * 3 + 1] * O;
438
+ n[h * 3] = z * r - I * m, n[h * 3 + 1] = L, n[h * 3 + 2] = z * m + I * r;
439
+ const B = this.nB[h] * 0.3;
440
+ e[h * 3] = i[g * 3] * B + 0.05 + u[g * 3] * w * 2.4, e[h * 3 + 1] = i[g * 3 + 1] * B + 0.06 + u[g * 3 + 1] * w * 2.4, e[h * 3 + 2] = i[g * 3 + 2] * B + 0.12 + u[g * 3 + 2] * w * 2.4, s[h] = 0.3 + this.nB[h] * 0.2 + w * 0.5;
441
+ }
442
+ ht(this.nebGeo);
443
+ const v = U(this.anchorGeo, "position"), F = U(this.anchorGeo, "acol"), C = U(this.anchorGeo, "size"), P = this.burst.length;
444
+ for (let h = 0; h < P; h++) {
445
+ const g = c[h * 3], w = c[h * 3 + 2];
446
+ v[h * 3] = g * r - w * m, v[h * 3 + 1] = c[h * 3 + 1], v[h * 3 + 2] = g * m + w * r;
447
+ const d = this.burst[h], o = this.aNamed[h] ? 2.2 : 1.1;
448
+ F[h * 3] = i[h * 3] * o + u[h * 3] * d * 7, F[h * 3 + 1] = i[h * 3 + 1] * o + u[h * 3 + 1] * d * 7, F[h * 3 + 2] = i[h * 3 + 2] * o + u[h * 3 + 2] * d * 7, C[h] = (this.aNamed[h] ? 1.25 : 0.75) * (1 + d * 3.5);
449
+ }
450
+ ht(this.anchorGeo);
451
+ const p = this.edgeGeo.getAttribute("color").array, A = this.edgeA;
452
+ for (let h = 0; h < A.length; h++) {
453
+ const g = A[h], w = A[h ^ 1], d = Math.max(this.burst[g], this.burst[w] * 0.6);
454
+ p[h * 3] = i[g * 3] * 0.32 + 0.05 + u[g * 3] * d * 3, p[h * 3 + 1] = i[g * 3 + 1] * 0.32 + 0.06 + u[g * 3 + 1] * d * 3, p[h * 3 + 2] = i[g * 3 + 2] * 0.32 + 0.1 + u[g * 3 + 2] * d * 3;
455
+ }
456
+ this.edgeGeo.getAttribute("color").needsUpdate = !0;
457
+ }
458
+ updateRunCurrents(t, n) {
459
+ const e = U(this.runGeo, "position"), s = U(this.runGeo, "acol"), r = U(this.runGeo, "size"), m = n * rt, b = [0, 0, 0], c = [0, 0, 0];
460
+ for (let i = 0; i < k; i++) {
461
+ const u = this.runRef[i], v = this.rAlpha[i], F = i * Z;
462
+ if (!u || v < 0.01) {
463
+ for (let a = 0; a < Z; a++) r[F + a] = 0;
464
+ continue;
465
+ }
466
+ const C = H[i][0], P = H[i][1], p = Et(i);
467
+ for (let a = 0; a < 3; a++) {
468
+ b[a] = p + a * N / 3;
469
+ const M = u.steps[V[a]];
470
+ c[a] = M === "running" ? 2.2 : M === "done" ? 0.5 : 0;
471
+ }
472
+ const A = (t - u.handoffAt) / 1e3, h = u.handoffAt > 0 && A < 2.4, g = p + V.indexOf(u.handoffFrom) * N / 3, w = ((V.indexOf(u.handoffTo) - V.indexOf(u.handoffFrom)) % 3 + 3) % 3 * (N / 3), d = w * Math.min(1, 1 - Math.pow(1 - Math.min(1, A / 1.4), 3)), o = h ? 3.2 * (1 - A / 2.4) : 0, f = this.rCol[i];
473
+ for (let a = 0; a < Z; a++) {
474
+ const M = F + a, O = this.rTh[M] + m * this.rSp[M], z = ct + this.rRr[M] + 0.16 * Math.sin(3 * O + m * 0.6 + M);
475
+ e[M * 3] = C + Math.cos(O) * z, e[M * 3 + 1] = 0.25 + this.rY[M], e[M * 3 + 2] = P + Math.sin(O) * z;
476
+ let I = 0;
477
+ for (let E = 0; E < 3; E++) {
478
+ if (c[E] === 0) continue;
479
+ let $ = (O - b[E]) % N;
480
+ $ < -Math.PI ? $ += N : $ > Math.PI && ($ -= N), $ > Math.PI && ($ -= N), I += c[E] * Math.exp(-$ * $ * 2.2);
481
+ }
482
+ let L = 0;
483
+ if (h) {
484
+ let E = (O - g) % N;
485
+ if (E < 0 && (E += N), E <= d && E <= w + 0.1) {
486
+ const $ = Math.exp(-(d - E) * 2.2);
487
+ I += o * (0.4 + $), L = 0.6 * $;
488
+ }
489
+ }
490
+ const B = Math.exp(-this.rRr[M] * this.rRr[M] * 4), j = v * (0.32 + 0.5 * B + I);
491
+ s[M * 3] = (f.r + (1 - f.r) * L) * j, s[M * 3 + 1] = (f.g + (1 - f.g) * L) * j, s[M * 3 + 2] = (f.b + (1 - f.b) * L) * j, r[M] = 0.36 + 0.28 * B + I * 0.12;
492
+ }
493
+ }
494
+ ht(this.runGeo);
495
+ }
496
+ updateStreams(t, n) {
497
+ const e = U(this.streamGeo, "position"), s = U(this.streamGeo, "acol"), r = U(this.streamGeo, "size");
498
+ let m = 0;
499
+ const b = (p, A, h, g, w, d, o) => {
500
+ m >= Ot || (e[m * 3] = p, e[m * 3 + 1] = A, e[m * 3 + 2] = h, s[m * 3] = g, s[m * 3 + 1] = w, s[m * 3 + 2] = d, r[m] = o, m++);
501
+ }, c = (p, A, h, g, w) => {
502
+ const d = (p.x + A.x) / 2, o = (p.y + A.y) / 2 + h, f = (p.z + A.z) / 2, a = 1 - g;
503
+ return w.set(a * a * p.x + 2 * a * g * d + g * g * A.x, a * a * p.y + 2 * a * g * o + g * g * A.y, a * a * p.z + 2 * a * g * f + g * g * A.z);
504
+ };
505
+ for (let p = 0; p < k; p++) {
506
+ const A = this.runRef[p];
507
+ if (!A || !A.handoffAt) continue;
508
+ const h = (t - A.handoffAt) / 1e3;
509
+ if (h > 2.4) continue;
510
+ yt(p, V.indexOf(A.handoffFrom), R), yt(p, V.indexOf(A.handoffTo), W);
511
+ const g = this.rCol[p], w = 220;
512
+ for (let d = 0; d < w; d++) {
513
+ const o = (h - d / w * 1.4) / 0.9;
514
+ if (o < 0 || o > 1) continue;
515
+ c(R, W, 2.2, o, T);
516
+ const f = Math.sin(o * Math.PI) * 0.35, a = (1 - o * 0.4) * 2.4;
517
+ b(T.x + (et(d) - 0.5) * f, T.y + (et(d + 7) - 0.5) * f, T.z + (et(d + 13) - 0.5) * f, (g.r * 0.6 + 0.4) * a, (g.g * 0.6 + 0.4) * a, (g.b * 0.6 + 0.4) * a, 0.7 + (d % 9 === 0 ? 0.8 : 0));
518
+ }
519
+ }
520
+ for (const p of _.comets) {
521
+ const A = this.slotOf(p.from), h = this.slotOf(p.to);
522
+ if (!A || !h) continue;
523
+ const g = Math.min(1, (t - p.start) / p.dur), w = g < 0.5 ? 2 * g * g : 1 - Math.pow(-2 * g + 2, 2) / 2;
524
+ R.set(A.x, A.y, A.z), W.set(h.x, h.y, h.z);
525
+ const d = R.distanceTo(W), o = A.inst ? Mt[A.inst.type] : K, f = g >= 1 ? Math.max(0, 1 - (t - p.start - p.dur) / 250) : 1;
526
+ for (let a = 0; a < 90; a++) {
527
+ const M = w - a * 55e-4;
528
+ if (M < 0) break;
529
+ c(R, W, 1.2 + d * 0.16, M, T);
530
+ const O = a * 6e-3, z = (a === 0 ? 7 : 3.2 * Math.pow(1 - a / 90, 1.6)) * f;
531
+ b(T.x + (et(p.id + a) - 0.5) * O, T.y + (et(p.id * 3 + a) - 0.5) * O, T.z + (et(p.id * 7 + a) - 0.5) * O, (o.r * 0.7 + 0.3) * z, (o.g * 0.7 + 0.3) * z, (o.b * 0.7 + 0.3) * z, a === 0 ? 2.6 : 0.85 - a * 6e-3);
532
+ }
533
+ }
534
+ const i = this.beamGeo.getAttribute("position").array, u = this.beamGeo.getAttribute("color").array;
535
+ let v = 0;
536
+ const F = (p, A, h, g, w, d, o, f, a, M, O, z) => {
537
+ i.set([p, A, h, g, w, d], v * 6), u.set([o, f, a, M, O, z], v * 6), v++;
538
+ };
539
+ for (const p of _.flares) {
540
+ if (v >= Tt) break;
541
+ const A = this.slotOf(p.instance);
542
+ if (!A) continue;
543
+ const h = (t - p.start) / 2600;
544
+ if (h >= 1) continue;
545
+ this.anchorWorld(this.anchorIdx(p.node), W), R.set(A.x, A.y, A.z);
546
+ const g = p.op === "write", w = g ? K : A.inst ? Mt[A.inst.type] : K, d = (1 - h) * (g ? 1.6 : 1);
547
+ F(R.x, R.y, R.z, W.x, W.y, W.z, w.r * d * 0.6, w.g * d * 0.6, w.b * d * 0.6, w.r * d * 1.4, w.g * d * 1.4, w.b * d * 1.4);
548
+ for (let o = 0; o < 22; o++) {
549
+ let f = ((t - p.start) / 1e3 * 0.75 + o / 22) % 1;
550
+ g || (f = 1 - f), c(R, W, 1.2, f, T);
551
+ const a = 2.4 * d * Math.sin(f * Math.PI);
552
+ b(T.x, T.y, T.z, w.r * a, w.g * a, w.b * a, 0.55);
553
+ }
554
+ }
555
+ for (const p of _.mcpCalls) {
556
+ const A = this.slotOf(p.instance), h = _.mcpServers.get(p.server);
557
+ if (!A || !h) continue;
558
+ const g = (t - p.start) / p.dur;
559
+ if (g > 1) continue;
560
+ R.set(A.x, A.y, A.z), Gt(h.slot, W);
561
+ const w = p.phase === "call" ? R : W, d = p.phase === "call" ? W : R;
562
+ S.set(h.color);
563
+ const o = 1 - Math.pow(1 - g, 2);
564
+ for (let f = 0; f < 60; f++) {
565
+ const a = o - f * 8e-3;
566
+ if (a < 0) break;
567
+ c(w, d, 3, a, T);
568
+ const M = (f === 0 ? 6 : 2.6 * (1 - f / 60)) * (p.phase === "result" ? 1.2 : 1);
569
+ b(T.x, T.y, T.z, (S.r * 0.75 + 0.25) * M, (S.g * 0.75 + 0.25) * M, (S.b * 0.75 + 0.25) * M, f === 0 ? 2.2 : 0.7);
570
+ }
571
+ }
572
+ let C = 0;
573
+ const P = (p, A, h, g) => {
574
+ if (C >= kt) return;
575
+ const w = this.slotOf(p), d = _.mcpServers.get(A);
576
+ if (!w || !d) return;
577
+ C++, R.set(w.x, w.y, w.z), Gt(d.slot, W), S.set(d.color), h < 2 ? S.lerp(es, Math.min(1, h / 2)) : S.copy(es).lerp(Ls, Math.min(1, h - 2));
578
+ const o = g >= 0 ? (1 - g) * 1.2 : 0.5 + Math.min(1.8, h * 0.6), f = n * 2.2;
579
+ let a = R.x, M = R.y, O = R.z;
580
+ for (let z = 1; z <= wt; z++) {
581
+ const I = z / wt;
582
+ c(R, W, 3, I, T);
583
+ const L = 0.5 + 0.5 * Math.sin((I * 9 - f) * N * 0.5), B = o * (0.25 + 0.75 * L * L);
584
+ v < Tt + kt * wt && F(a, M, O, T.x, T.y, T.z, S.r * B, S.g * B, S.b * B, S.r * B, S.g * B, S.b * B), a = T.x, M = T.y, O = T.z;
585
+ }
586
+ if (g < 0) {
587
+ const z = 5 + Math.min(8, Math.floor(h * 3));
588
+ for (let I = 0; I < z; I++) {
589
+ const L = (n * (0.45 + h * 0.15) + I / z) % 1;
590
+ c(R, W, 3, L, T);
591
+ const B = o * 0.9;
592
+ b(T.x, T.y, T.z, S.r * B, S.g * B, S.b * B, 0.8);
593
+ }
594
+ } else {
595
+ const z = 1 - Math.min(1, g * 1.6);
596
+ for (let I = 0; I < 26; I++) {
597
+ const L = z + I * 0.012;
598
+ if (L > 1) break;
599
+ c(R, W, 3, L, T);
600
+ const B = (I === 0 ? 9 : 4 * (1 - I / 26)) * (1 - g * 0.5);
601
+ b(T.x, T.y, T.z, 0.6 * B + S.r * B * 0.4, 0.6 * B + S.g * B * 0.4, 0.6 * B + S.b * B * 0.4, I === 0 ? 2.8 : 0.9);
602
+ }
603
+ }
604
+ };
605
+ for (const p of _.mcpPending.values()) P(p.instance, p.server, Qt(p, t), -1);
606
+ for (const p of _.mcpResolved) P(p.instance, p.server, (p.resolvedAt - p.since) / 1e3, Math.min(1, (t - p.resolvedAt) / 700));
607
+ for (let p = m; p < Ot && r[p] !== 0; p++)
608
+ r[p] = 0;
609
+ this.streamGeo.setDrawRange(0, Math.max(m, 1)), ht(this.streamGeo), this.beamGeo.setDrawRange(0, v * 2), this.beamGeo.getAttribute("position").needsUpdate = !0, this.beamGeo.getAttribute("color").needsUpdate = !0;
610
+ }
611
+ setInst(t, n, e, s, r, m, b, c = 0, i = 0, u = 0) {
612
+ Q.position.set(e, s, r), Q.rotation.set(c, i, u), Q.scale.setScalar(Math.max(1e-4, m)), Q.updateMatrix(), t.setMatrixAt(n, Q.matrix), t.setColorAt(n, b);
613
+ }
614
+ updateMeshes(t, n, e) {
615
+ const s = U(this.glowGeo, "position"), r = U(this.glowGeo, "acol"), m = U(this.glowGeo, "size"), b = (i, u, v, F, C, P, p) => {
616
+ s[i * 3] = u, s[i * 3 + 1] = v, s[i * 3 + 2] = F, r[i * 3] = C.r * P, r[i * 3 + 1] = C.g * P, r[i * 3 + 2] = C.b * P, m[i] = p;
617
+ };
618
+ let c = null;
619
+ for (let i = 0; i < q; i++) {
620
+ const u = this.slots[i];
621
+ if (!u.used || !u.inst) {
622
+ this.setInst(this.cores, i, 0, -999, 0, 0, S.setRGB(0, 0, 0)), this.setInst(this.hits, i, 0, -999, 0, 0, S), m[i] = 0;
623
+ continue;
624
+ }
625
+ u.id === this.selectedId && (c = u);
626
+ const v = u.inst, F = (t - v.bornAt) / 1e3, C = Math.exp(-F * 3.5), P = v.exitAt ? (t - v.exitAt) / 1e3 : -1, p = P >= 0 ? Math.exp(-P * 5) : 0, h = v.status === "thinking" && !v.exitAt ? 0.1 * Math.sin(n * 9 + i) : 0, g = P >= 0 ? Math.pow(u.p, 1.6) : u.p, w = Jt(), d = (g * (1 + u.e * 0.45 + h) + p * 0.9 + C * 0.6) * w;
627
+ S.setRGB(u.r, u.g, u.b).multiplyScalar(1.3 + u.bright * 1.5 + u.e * 1.1), S.lerp(J.setRGB(4, 4, 4), Math.min(1, C + p)), this.setInst(this.cores, i, u.x, u.y, u.z, d, S, n * u.omega * 0.3, n * u.omega, 0), this.setInst(this.hits, i, u.x, u.y, u.z, v.exitAt ? 0 : 1, S), S.setRGB(u.r, u.g, u.b), b(i, u.x, u.y, u.z, S, (0.3 + u.bright * 0.4 + u.e * 0.5 + C * 2 + p * 2.5) * u.p + p, (5 + u.e * 4 + C * 10 + p * 14) * Math.max(u.p, p) * w);
628
+ }
629
+ c ? (this.selRing.visible = !0, this.selRing.position.set(c.x, c.y, c.z), this.selRing.rotation.y = n * 1.5, this.selRing.scale.setScalar(1 + 0.08 * Math.sin(n * 4)), this.selRing.material.color.setRGB(c.r * 3, c.g * 3, c.b * 3)) : this.selRing.visible = !1;
630
+ for (let i = 0; i < k; i++) {
631
+ const u = this.runRef[i], v = this.rAlpha[i];
632
+ for (let F = 0; F < 3; F++) {
633
+ const C = i * 3 + F, P = q + C;
634
+ if (!u || v < 0.01) {
635
+ this.setInst(this.attractors, C, 0, -999, 0, 0, S.setRGB(0, 0, 0)), this.setInst(this.stepRings, C, 0, -999, 0, 0, S), m[P] = 0;
636
+ continue;
637
+ }
638
+ yt(i, F, R);
639
+ const p = u.steps[V[F]], A = this.rCol[i];
640
+ let h = 0.6, g = 0.5, w = 0.25, d = 0.9, o = 0.12, f = 4;
641
+ if (S.copy(A), p === "running") {
642
+ const a = 0.5 + 0.5 * Math.sin(n * 5);
643
+ h = 1.15 + a * 0.2, S.lerp(K, 0.45), g = 3 + a * 1.5, w = 1.4 + a, d = 1.15 + a * 0.25, o = 1.1 + a * 0.6, f = 12;
644
+ } else p === "done" ? (h = 0.85, g = 1.8, w = 0.7, d = 0.95, o = 0.4, f = 6) : p === "failed" && S.copy(Es);
645
+ if (u.handoffAt && V[F] === u.handoffTo) {
646
+ const a = (t - u.handoffAt) / 1e3 - 1.2;
647
+ if (a > 0 && a < 1) {
648
+ const M = Math.exp(-a * 4);
649
+ h += M * 0.8, o += M * 2, f += M * 10;
650
+ }
651
+ }
652
+ J.copy(S).multiplyScalar(g * v), this.setInst(this.attractors, C, R.x, R.y, R.z, h, J, 0, n * 0.6, 0), J.copy(S).multiplyScalar(w * v), this.setInst(this.stepRings, C, R.x, R.y, R.z, d, J, 0, p === "running" ? n * 1.6 : 0.3, 0), b(P, R.x, R.y, R.z, S, o * v, f);
653
+ }
654
+ }
655
+ for (let i = 0; i < ot; i++) {
656
+ const u = q + k * 3 + i;
657
+ this.setInst(this.pulsars, i, 0, -999, 0, 0, S.setRGB(0, 0, 0)), this.setInst(this.pulsarBeams, i, 0, -999, 0, 0, S), m[u] = 0;
658
+ }
659
+ for (const i of _.mcpServers.values()) {
660
+ const u = i.slot % ot, v = q + k * 3 + u;
661
+ Gt(i.slot, R);
662
+ const F = Math.exp(-((t - i.activeAt) / 1e3) * 2.5), C = i.inflight > 0 ? 1 : 0;
663
+ this.mcpSpin[u] += e * (0.4 + C * 3.5) * rt;
664
+ const P = 0.5 + 0.5 * Math.sin(n * (C ? 9 : 2.2) + u);
665
+ S.set(i.color), J.copy(S).multiplyScalar(1.6 + C * 1.6 + F * 3 + P * 0.6), this.setInst(this.pulsars, u, R.x, R.y, R.z, 1 + F * 0.6 + C * 0.2 * P, J, 0, this.mcpSpin[u], 0), J.copy(S).multiplyScalar(0.25 + C * 0.9 * P + F * 0.8), this.setInst(this.pulsarBeams, u, R.x, R.y, R.z, 1 + C * 0.3, J, 0.5 * Math.sin(this.mcpSpin[u] * 0.5), this.mcpSpin[u], 0.35 + 0.3 * Math.cos(this.mcpSpin[u])), b(v, R.x, R.y, R.z, S, 0.6 + C * 0.8 * P + F * 1.6, 9 + F * 12 + C * 4);
666
+ }
667
+ for (let i = 0; i < st; i++) {
668
+ const u = (t - this.ringStart[i]) / (this.ringDur[i] * 1e3);
669
+ if (u < 0 || u >= 1) {
670
+ this.setInst(this.rings, i, 0, -999, 0, 0, S.setRGB(0, 0, 0));
671
+ continue;
672
+ }
673
+ const v = 1 - Math.pow(1 - u, 3), F = (1 - u) * (1 - u);
674
+ S.setRGB(this.ringCol[i * 3] * F, this.ringCol[i * 3 + 1] * F, this.ringCol[i * 3 + 2] * F), this.setInst(this.rings, i, this.ringPos[i * 3], this.ringPos[i * 3 + 1], this.ringPos[i * 3 + 2], 0.15 + this.ringMax[i] * v, S);
675
+ }
676
+ for (const i of [this.cores, this.hits, this.attractors, this.stepRings, this.rings, this.pulsars, this.pulsarBeams])
677
+ i.instanceMatrix.needsUpdate = !0, i.instanceColor && (i.instanceColor.needsUpdate = !0);
678
+ ht(this.glowGeo);
679
+ }
680
+ }
681
+ function js(l, t, n) {
682
+ const [e, s] = H[l];
683
+ let r = l === 1 ? 0.74 : 1;
684
+ const m = dt.laneExpanded[l] > 0;
685
+ return m && (r *= 0.82), t.set(e * r, (m ? 5.2 : 1.8) + Math.sin(n * 0.6 + l * 2.1) * 0.2, s * r);
686
+ }
687
+ function Ds() {
688
+ return /* @__PURE__ */ G(Ss, { place: js, radius: 1.7, variant: "swarm", pointSize: 1.1 });
689
+ }
690
+ const St = new x.Vector3();
691
+ function Us({ engine: l, onSelect: t }) {
692
+ const n = ps((s) => s.gl);
693
+ is(() => {
694
+ l.material.uniforms.uPR.value = n.getPixelRatio();
695
+ }, [l, n]), bt((s, r) => {
696
+ Cs(), vs(), l.update(r, performance.now(), s.clock.elapsedTime);
697
+ });
698
+ const e = (s) => {
699
+ var m;
700
+ s.stopPropagation();
701
+ const r = s.instanceId !== void 0 ? (m = l.slots[s.instanceId]) == null ? void 0 : m.id : null;
702
+ r && l.slots[s.instanceId].used && t(r);
703
+ };
704
+ return /* @__PURE__ */ ft("group", { children: [
705
+ /* @__PURE__ */ G("points", { geometry: l.fieldGeo, material: l.material, frustumCulled: !1 }),
706
+ /* @__PURE__ */ G("points", { geometry: l.runGeo, material: l.material, frustumCulled: !1 }),
707
+ /* @__PURE__ */ G("points", { geometry: l.nebGeo, material: l.material, frustumCulled: !1 }),
708
+ /* @__PURE__ */ G("points", { geometry: l.anchorGeo, material: l.material, frustumCulled: !1 }),
709
+ /* @__PURE__ */ G("points", { geometry: l.streamGeo, material: l.material, frustumCulled: !1 }),
710
+ /* @__PURE__ */ G("points", { geometry: l.glowGeo, material: l.material, frustumCulled: !1 }),
711
+ /* @__PURE__ */ G("lineSegments", { geometry: l.edgeGeo, frustumCulled: !1, children: /* @__PURE__ */ G("lineBasicMaterial", { vertexColors: !0, transparent: !0, blending: x.AdditiveBlending, depthWrite: !1, toneMapped: !1 }) }),
712
+ /* @__PURE__ */ G("lineSegments", { geometry: l.beamGeo, frustumCulled: !1, children: /* @__PURE__ */ G("lineBasicMaterial", { vertexColors: !0, transparent: !0, blending: x.AdditiveBlending, depthWrite: !1, toneMapped: !1 }) }),
713
+ /* @__PURE__ */ G("primitive", { object: l.cores }),
714
+ /* @__PURE__ */ G("primitive", { object: l.attractors }),
715
+ /* @__PURE__ */ G("primitive", { object: l.stepRings }),
716
+ /* @__PURE__ */ G("primitive", { object: l.rings }),
717
+ /* @__PURE__ */ G("primitive", { object: l.pulsars }),
718
+ /* @__PURE__ */ G("primitive", { object: l.pulsarBeams }),
719
+ /* @__PURE__ */ G("primitive", { object: l.selRing }),
720
+ /* @__PURE__ */ G(
721
+ "primitive",
722
+ {
723
+ object: l.hits,
724
+ onClick: e,
725
+ onPointerOver: () => document.body.style.cursor = "pointer",
726
+ onPointerOut: () => document.body.style.cursor = ""
727
+ }
728
+ )
729
+ ] });
730
+ }
731
+ function Ns({ run: l }) {
732
+ Is();
733
+ const t = l.slot % k, n = ns(() => V.map((s, r) => yt(t, r, new x.Vector3(), as(l.id)).toArray()), [t, l.id]), e = (s) => s === "running" ? l.color : s === "done" ? "#cbd5e1" : s === "failed" ? "#fecaca" : "#64748b";
734
+ return /* @__PURE__ */ ft("group", { children: [
735
+ /* @__PURE__ */ G(
736
+ ut,
737
+ {
738
+ position: [H[t][0], 0.6, H[t][1]],
739
+ text: `${l.hasSteps ? "hatchet · " : ""}${l.topic}`,
740
+ secondary: V.map((s, r) => ({ text: `${r ? " " : ""}${s.toUpperCase()}`, color: e(l.steps[s]) })),
741
+ secondarySize: 0.24,
742
+ color: l.color,
743
+ size: 0.34,
744
+ maxWidth: 10,
745
+ fadeMs: 300,
746
+ pxRange: [10, 14]
747
+ }
748
+ ),
749
+ V.map((s, r) => /* @__PURE__ */ G(
750
+ ut,
751
+ {
752
+ position: [n[r][0], n[r][1] + 1.1, n[r][2]],
753
+ text: s,
754
+ font: "mono",
755
+ plate: "none",
756
+ uppercase: !0,
757
+ letterSpacing: 0.08,
758
+ textColor: l.color,
759
+ size: 0.24,
760
+ opacity: l.steps[s] === "running" ? 1 : l.steps[s] === "done" ? 0.75 : 0.55,
761
+ fadeMs: 300,
762
+ pxRange: [7.5, 10.5]
763
+ },
764
+ s
765
+ ))
766
+ ] });
767
+ }
768
+ function Ws() {
769
+ const [l, t] = jt([]), n = tt(/* @__PURE__ */ new Set()), e = tt(-1);
770
+ return bt(() => {
771
+ const s = _.runs;
772
+ let r = s.size !== n.current.size || e.current !== dt.version;
773
+ if (!r)
774
+ for (const m of s.keys()) n.current.has(m) || (r = !0);
775
+ r && (n.current = new Set(s.keys()), e.current = dt.version, t([...s.values()].filter((m) => Lt(m.id))));
776
+ }), /* @__PURE__ */ G(_t, { children: l.map((s) => /* @__PURE__ */ G(Ns, { run: s }, s.id)) });
777
+ }
778
+ function $s() {
779
+ const [l, t] = jt([]), n = tt(0);
780
+ return bt(() => {
781
+ _.mcpServers.size !== n.current && (n.current = _.mcpServers.size, t([..._.mcpServers.values()].map((e) => ({ name: e.name, slot: e.slot, color: e.color }))));
782
+ }), /* @__PURE__ */ G(_t, { children: l.map((e) => {
783
+ const s = Gt(e.slot, new x.Vector3());
784
+ return /* @__PURE__ */ G(ut, { position: [s.x, s.y + 1.5, s.z], text: `mcp · ${e.name}`, color: e.color, size: 0.3, pxRange: [9, 13] }, e.name);
785
+ }) });
786
+ }
787
+ function Xs({ engine: l }) {
788
+ const t = tt(null), n = tt(null), e = tt("");
789
+ return bt(() => {
790
+ var c;
791
+ const s = l.selectedId ?? _.focus, r = s ? l.slotOf(s) : null, m = !!r && !!r.inst && !r.inst.exitAt;
792
+ if ((c = n.current) == null || c.setOpacity(m ? 1 : 0), !r || !r.inst || !t.current || !n.current) return;
793
+ t.current.position.set(r.x, r.y + 1.25, r.z);
794
+ const b = `${r.inst.name} · ${r.inst.status}`;
795
+ b !== e.current && (e.current = b, n.current.setText(b), n.current.setColor(rs[r.inst.type]));
796
+ }), /* @__PURE__ */ G("group", { ref: t, children: /* @__PURE__ */ G(ut, { ref: n, text: "", size: 0.3, opacity: 0, fadeMs: 300, pxRange: [9, 13], renderOrder: 24 }) });
797
+ }
798
+ function qs({ engine: l }) {
799
+ const t = tt(null), n = tt(null), e = tt("");
800
+ return bt(() => {
801
+ const s = l.lastFlare;
802
+ if (!s || !t.current || !n.current) return;
803
+ const r = (performance.now() - s.at) / 1e3;
804
+ n.current.setOpacity(r < 2.2 ? 1 : 0), l.anchorWorld(s.idx, St), t.current.position.set(St.x, St.y + 0.9, St.z);
805
+ const m = `${s.op === "write" ? "wrote" : "read"} · ${s.name}`;
806
+ m !== e.current && (e.current = m, n.current.setText(m), n.current.setColor(s.op === "write" ? "#ffffff" : "#a5b4fc"));
807
+ }), /* @__PURE__ */ G("group", { ref: t, children: /* @__PURE__ */ G(ut, { ref: n, text: "", size: 0.28, opacity: 0, fadeMs: 400, pxRange: [8.5, 12], renderOrder: 24 }) });
808
+ }
809
+ function Hs({ galaxy: l, selected: t, onSelect: n }) {
810
+ const e = ns(() => new _s(l), [l]);
811
+ return is(() => () => e.dispose(), [e]), e.selectedId = t, /* @__PURE__ */ ft(_t, { children: [
812
+ /* @__PURE__ */ G(Us, { engine: e, onSelect: n }),
813
+ /* @__PURE__ */ G(Ds, {}),
814
+ /* @__PURE__ */ G(Ws, {}),
815
+ /* @__PURE__ */ G($s, {}),
816
+ /* @__PURE__ */ G(Xs, { engine: e }),
817
+ /* @__PURE__ */ G(qs, { engine: e }),
818
+ /* @__PURE__ */ G(ut, { position: [0, -1.3, 0], text: "FalkorDB", color: "#a5b4fc", size: 0.34, pxRange: [9.5, 13] })
819
+ ] });
820
+ }
821
+ function ee() {
822
+ const l = zs(), [t, n] = jt(null);
823
+ return /* @__PURE__ */ ft("div", { className: "scene-root", children: [
824
+ /* @__PURE__ */ ft(
825
+ us,
826
+ {
827
+ camera: { position: [0, 25, 28], fov: 50 },
828
+ dpr: [1, 1.75],
829
+ gl: { antialias: !1, powerPreference: "high-performance" },
830
+ onPointerMissed: () => n(null),
831
+ children: [
832
+ /* @__PURE__ */ G("color", { attach: "background", args: ["#020309"] }),
833
+ /* @__PURE__ */ G(Hs, { galaxy: l, selected: t, onSelect: n }),
834
+ /* @__PURE__ */ G(ds, { makeDefault: !0, enableDamping: !0, dampingFactor: 0.06, minDistance: 10, maxDistance: 70, maxPolarAngle: Math.PI * 0.47 }),
835
+ /* @__PURE__ */ ft(ms, { multisampling: 0, children: [
836
+ /* @__PURE__ */ G(gs, { mipmapBlur: !0, intensity: 1.25, luminanceThreshold: 0.22, luminanceSmoothing: 0.25, radius: 0.78 }),
837
+ /* @__PURE__ */ G(Ms, { eskil: !1, offset: 0.22, darkness: 0.85 }),
838
+ /* @__PURE__ */ G(ys, { opacity: 0.03 })
839
+ ] })
840
+ ]
841
+ }
842
+ ),
843
+ /* @__PURE__ */ G(Gs, { title: "flow · murmuration", subtitle: "agents are eddies condensing out of the current · hatchet runs are vortices · the knowledge graph is the nebula", selected: t, onClose: () => n(null) })
844
+ ] });
845
+ }
846
+ export {
847
+ ee as default
848
+ };