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