agentglow 0.4.1 → 0.4.3

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