@tonyclaw/agent-inspector 3.0.24 → 3.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.output/nitro.json +1 -1
- package/.output/public/assets/{CompareDrawer-BC52FYwn.js → CompareDrawer-SZRUDQc9.js} +1 -1
- package/.output/public/assets/ProxyViewerContainer-BJvwOrSi.js +4234 -0
- package/.output/public/assets/{ReplayDialog-BcKsarKt.js → ReplayDialog-DgfmqiM3.js} +1 -1
- package/.output/public/assets/{RequestAnatomy-DR0uGpCj.js → RequestAnatomy-CS6c7Qfn.js} +1 -1
- package/.output/public/assets/{ResponseView-kxAAPfmn.js → ResponseView-C0Ri_5gm.js} +2 -2
- package/.output/public/assets/{StreamingChunkSequence-YQR0PjQj.js → StreamingChunkSequence-7dYcHWyZ.js} +1 -1
- package/.output/public/assets/{_sessionId-DRl-Y9om.js → _sessionId-D-V84cgw.js} +1 -1
- package/.output/public/assets/{index-CQbrc-hi.js → index-CSIL7-MK.js} +3 -3
- package/.output/public/assets/index-CmeF5XXS.css +1 -0
- package/.output/public/assets/{index-CcSIBI4L.js → index-DgFWCxOs.js} +1 -1
- package/.output/public/assets/{index-ZrMgyEZV.js → index-DrVJsks2.js} +1 -1
- package/.output/public/assets/{json-viewer-CS5pwnEA.js → json-viewer-C9Ji3gYN.js} +1 -1
- package/.output/server/_libs/lucide-react.mjs +245 -217
- package/.output/server/_libs/three.mjs +26016 -0
- package/.output/server/{_sessionId-BLk2xPkR.mjs → _sessionId-BQ6YQOO1.mjs} +7 -6
- package/.output/server/_ssr/{CompareDrawer-Cw7Dseo3.mjs → CompareDrawer-CqNzIeMR.mjs} +8 -7
- package/.output/server/_ssr/{ProxyViewerContainer-D8SB0zyQ.mjs → ProxyViewerContainer-CMC7Vsbw.mjs} +1164 -405
- package/.output/server/_ssr/{ReplayDialog-B-YMhZkE.mjs → ReplayDialog-D9p_LaTr.mjs} +9 -8
- package/.output/server/_ssr/{RequestAnatomy-a9d8UTYZ.mjs → RequestAnatomy-B4ge3qNZ.mjs} +8 -7
- package/.output/server/_ssr/{ResponseView-PzaZS4CN.mjs → ResponseView-BCqMKApI.mjs} +8 -7
- package/.output/server/_ssr/{StreamingChunkSequence-C21_TCXk.mjs → StreamingChunkSequence-BA4zTLE4.mjs} +8 -7
- package/.output/server/_ssr/{index-CrCeNP7H.mjs → index-CzxhDjlq.mjs} +7 -6
- package/.output/server/_ssr/index.mjs +2 -2
- package/.output/server/_ssr/{json-viewer-Di2gxs9H.mjs → json-viewer-B3qV6iEJ.mjs} +8 -7
- package/.output/server/_ssr/{router-BJzdUbcH.mjs → router-CZe_R31M.mjs} +4 -4
- package/.output/server/{_tanstack-start-manifest_v-CGBTdAYC.mjs → _tanstack-start-manifest_v-B50VTLrH.mjs} +1 -1
- package/.output/server/index.mjs +68 -68
- package/package.json +3 -1
- package/src/components/ProxyViewer.tsx +2 -280
- package/src/components/inspector-pet/InspectorPet.tsx +405 -0
- package/src/components/inspector-pet/InspectorPetCrab3D.tsx +455 -0
- package/src/components/inspector-pet/inspectorPetLogic.ts +258 -0
- package/src/components/providers/ProviderForm.tsx +238 -163
- package/src/components/providers/ProvidersPanel.tsx +16 -6
- package/src/components/providers/providerFormCapabilities.ts +36 -0
- package/styles/globals.css +64 -28
- package/.output/public/assets/ProxyViewerContainer-WuChOrSS.js +0 -127
- package/.output/public/assets/index-DQeXi4Rv.css +0 -1
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { type JSX, useEffect, useRef, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
ACESFilmicToneMapping,
|
|
4
|
+
AmbientLight,
|
|
5
|
+
type BufferGeometry,
|
|
6
|
+
CircleGeometry,
|
|
7
|
+
Color,
|
|
8
|
+
CylinderGeometry,
|
|
9
|
+
DirectionalLight,
|
|
10
|
+
Group,
|
|
11
|
+
HemisphereLight,
|
|
12
|
+
type Material,
|
|
13
|
+
Mesh,
|
|
14
|
+
MeshBasicMaterial,
|
|
15
|
+
MeshPhysicalMaterial,
|
|
16
|
+
type Object3D,
|
|
17
|
+
OrthographicCamera,
|
|
18
|
+
PointLight,
|
|
19
|
+
Scene,
|
|
20
|
+
SphereGeometry,
|
|
21
|
+
SRGBColorSpace,
|
|
22
|
+
Vector3,
|
|
23
|
+
WebGLRenderer,
|
|
24
|
+
} from "three";
|
|
25
|
+
import { CrabLogo } from "../ui/crab-logo";
|
|
26
|
+
import type { InspectorPetMood } from "./inspectorPetLogic";
|
|
27
|
+
|
|
28
|
+
type InspectorPetCrab3DProps = {
|
|
29
|
+
mood: InspectorPetMood;
|
|
30
|
+
moving: boolean;
|
|
31
|
+
reduceMotion: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type AnimatedLeg = {
|
|
35
|
+
group: Group;
|
|
36
|
+
phase: number;
|
|
37
|
+
side: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type AnimatedEye = {
|
|
41
|
+
group: Group;
|
|
42
|
+
phase: number;
|
|
43
|
+
pupil: Mesh;
|
|
44
|
+
pupilRest: Vector3;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type AnimatedPincer = {
|
|
48
|
+
direction: number;
|
|
49
|
+
mesh: Mesh;
|
|
50
|
+
restRotationZ: number;
|
|
51
|
+
restY: number;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type AnimatedClaw = {
|
|
55
|
+
group: Group;
|
|
56
|
+
pincers: AnimatedPincer[];
|
|
57
|
+
scale: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type CrabSceneParts = {
|
|
61
|
+
bodyMaterial: MeshPhysicalMaterial;
|
|
62
|
+
dominantClaw: AnimatedClaw;
|
|
63
|
+
eyes: AnimatedEye[];
|
|
64
|
+
legs: AnimatedLeg[];
|
|
65
|
+
rimLight: PointLight;
|
|
66
|
+
root: Group;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function createRod(
|
|
70
|
+
start: Vector3,
|
|
71
|
+
end: Vector3,
|
|
72
|
+
radius: number,
|
|
73
|
+
material: MeshPhysicalMaterial,
|
|
74
|
+
): Mesh {
|
|
75
|
+
const direction = end.clone().sub(start);
|
|
76
|
+
const length = direction.length();
|
|
77
|
+
const rod = new Mesh(new CylinderGeometry(radius, radius * 0.9, length, 12), material);
|
|
78
|
+
rod.position.copy(start.clone().add(end).multiplyScalar(0.5));
|
|
79
|
+
rod.quaternion.setFromUnitVectors(new Vector3(0, 1, 0), direction.normalize());
|
|
80
|
+
return rod;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function addClaw(
|
|
84
|
+
root: Group,
|
|
85
|
+
side: number,
|
|
86
|
+
shellMaterial: MeshPhysicalMaterial,
|
|
87
|
+
accentMaterial: MeshPhysicalMaterial,
|
|
88
|
+
): AnimatedClaw {
|
|
89
|
+
const clawScale = side < 0 ? 1.5 : 0.68;
|
|
90
|
+
const clawGroup = new Group();
|
|
91
|
+
const pincers: AnimatedPincer[] = [];
|
|
92
|
+
root.add(clawGroup);
|
|
93
|
+
|
|
94
|
+
const shoulder = new Vector3(side * 1.2, 0.25, -0.05);
|
|
95
|
+
const wrist = new Vector3(side * (1.65 + clawScale * 0.18), 0.5, 0);
|
|
96
|
+
const arm = createRod(shoulder, wrist, 0.16 * clawScale, accentMaterial);
|
|
97
|
+
clawGroup.add(arm);
|
|
98
|
+
|
|
99
|
+
const palm = new Mesh(new SphereGeometry(0.55, 24, 16), shellMaterial);
|
|
100
|
+
palm.position.set(side * (1.95 + clawScale * 0.16), 0.62, 0.05);
|
|
101
|
+
palm.scale.set(1.05 * clawScale, 0.72 * clawScale, 0.55 * clawScale);
|
|
102
|
+
clawGroup.add(palm);
|
|
103
|
+
|
|
104
|
+
for (const pincerDirection of [-1, 1]) {
|
|
105
|
+
const pincer = new Mesh(new SphereGeometry(0.36, 20, 14), accentMaterial);
|
|
106
|
+
pincer.position.set(
|
|
107
|
+
side * (2.22 + clawScale * 0.26),
|
|
108
|
+
0.62 + pincerDirection * 0.24 * clawScale,
|
|
109
|
+
0.08,
|
|
110
|
+
);
|
|
111
|
+
pincer.scale.set(1.05 * clawScale, 0.34 * clawScale, 0.42 * clawScale);
|
|
112
|
+
pincer.rotation.z = pincerDirection * side * 0.42;
|
|
113
|
+
clawGroup.add(pincer);
|
|
114
|
+
pincers.push({
|
|
115
|
+
direction: pincerDirection,
|
|
116
|
+
mesh: pincer,
|
|
117
|
+
restRotationZ: pincer.rotation.z,
|
|
118
|
+
restY: pincer.position.y,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return { group: clawGroup, pincers, scale: clawScale };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function pinchPulse(cycleTime: number, start: number, duration: number): number {
|
|
126
|
+
const progress = (cycleTime - start) / duration;
|
|
127
|
+
if (progress <= 0 || progress >= 1) return 0;
|
|
128
|
+
return Math.sin(progress * Math.PI);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function dominantClawGrip(elapsed: number): number {
|
|
132
|
+
const cycleTime = elapsed % 6.8;
|
|
133
|
+
return Math.max(pinchPulse(cycleTime, 0.72, 0.82), pinchPulse(cycleTime, 1.72, 0.68));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function addEyes(
|
|
137
|
+
root: Group,
|
|
138
|
+
shellMaterial: MeshPhysicalMaterial,
|
|
139
|
+
eyeMaterial: MeshPhysicalMaterial,
|
|
140
|
+
): AnimatedEye[] {
|
|
141
|
+
const eyes: AnimatedEye[] = [];
|
|
142
|
+
for (const side of [-1, 1]) {
|
|
143
|
+
const stalkStart = new Vector3(side * 0.48, 0.68, 0.05);
|
|
144
|
+
const stalkEnd = new Vector3(side * 0.1, 0.82, 0.07);
|
|
145
|
+
const eyeGroup = new Group();
|
|
146
|
+
eyeGroup.position.copy(stalkStart);
|
|
147
|
+
eyeGroup.add(createRod(new Vector3(0, 0, 0), stalkEnd, 0.1, shellMaterial));
|
|
148
|
+
|
|
149
|
+
const eye = new Mesh(new SphereGeometry(0.24, 20, 16), eyeMaterial);
|
|
150
|
+
eye.position.copy(stalkEnd);
|
|
151
|
+
eye.scale.set(1, 1, 0.85);
|
|
152
|
+
eyeGroup.add(eye);
|
|
153
|
+
|
|
154
|
+
const pupil = new Mesh(
|
|
155
|
+
new SphereGeometry(0.105, 16, 12),
|
|
156
|
+
new MeshPhysicalMaterial({ color: 0x111827, roughness: 0.25 }),
|
|
157
|
+
);
|
|
158
|
+
const pupilRest = new Vector3(stalkEnd.x, stalkEnd.y, stalkEnd.z + 0.2);
|
|
159
|
+
pupil.position.copy(pupilRest);
|
|
160
|
+
eyeGroup.add(pupil);
|
|
161
|
+
root.add(eyeGroup);
|
|
162
|
+
eyes.push({
|
|
163
|
+
group: eyeGroup,
|
|
164
|
+
phase: side < 0 ? 0 : Math.PI / 3,
|
|
165
|
+
pupil,
|
|
166
|
+
pupilRest,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return eyes;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function addLegs(root: Group, legMaterial: MeshPhysicalMaterial): AnimatedLeg[] {
|
|
173
|
+
const legs: AnimatedLeg[] = [];
|
|
174
|
+
for (const side of [-1, 1]) {
|
|
175
|
+
for (let index = 0; index < 4; index += 1) {
|
|
176
|
+
const leg = new Group();
|
|
177
|
+
const baseY = -0.3 - index * 0.22;
|
|
178
|
+
leg.position.set(side * (0.8 + index * 0.12), baseY, -0.18);
|
|
179
|
+
leg.add(
|
|
180
|
+
createRod(
|
|
181
|
+
new Vector3(0, 0, 0),
|
|
182
|
+
new Vector3(side * (0.62 + index * 0.06), -0.34, 0),
|
|
183
|
+
0.095,
|
|
184
|
+
legMaterial,
|
|
185
|
+
),
|
|
186
|
+
);
|
|
187
|
+
leg.add(
|
|
188
|
+
createRod(
|
|
189
|
+
new Vector3(side * (0.58 + index * 0.06), -0.31, 0),
|
|
190
|
+
new Vector3(side * (1.02 + index * 0.08), -0.88 + index * 0.07, 0.04),
|
|
191
|
+
0.075,
|
|
192
|
+
legMaterial,
|
|
193
|
+
),
|
|
194
|
+
);
|
|
195
|
+
root.add(leg);
|
|
196
|
+
legs.push({ group: leg, phase: index * Math.PI + (side > 0 ? Math.PI / 2 : 0), side });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return legs;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function createCrabScene(scene: Scene): CrabSceneParts {
|
|
203
|
+
const shellMaterial = new MeshPhysicalMaterial({
|
|
204
|
+
color: 0xf59e0b,
|
|
205
|
+
roughness: 0.34,
|
|
206
|
+
metalness: 0.04,
|
|
207
|
+
clearcoat: 0.78,
|
|
208
|
+
clearcoatRoughness: 0.18,
|
|
209
|
+
emissive: new Color(0x000000),
|
|
210
|
+
emissiveIntensity: 0,
|
|
211
|
+
});
|
|
212
|
+
const accentMaterial = new MeshPhysicalMaterial({
|
|
213
|
+
color: 0xfb923c,
|
|
214
|
+
roughness: 0.42,
|
|
215
|
+
metalness: 0.02,
|
|
216
|
+
clearcoat: 0.52,
|
|
217
|
+
clearcoatRoughness: 0.28,
|
|
218
|
+
});
|
|
219
|
+
const legMaterial = new MeshPhysicalMaterial({
|
|
220
|
+
color: 0xd97706,
|
|
221
|
+
roughness: 0.48,
|
|
222
|
+
clearcoat: 0.35,
|
|
223
|
+
clearcoatRoughness: 0.35,
|
|
224
|
+
});
|
|
225
|
+
const eyeMaterial = new MeshPhysicalMaterial({
|
|
226
|
+
color: 0xfffbeb,
|
|
227
|
+
roughness: 0.22,
|
|
228
|
+
clearcoat: 0.8,
|
|
229
|
+
clearcoatRoughness: 0.12,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const root = new Group();
|
|
233
|
+
root.rotation.x = -0.12;
|
|
234
|
+
root.rotation.y = -0.08;
|
|
235
|
+
root.scale.setScalar(1.08);
|
|
236
|
+
scene.add(root);
|
|
237
|
+
|
|
238
|
+
const shadow = new Mesh(
|
|
239
|
+
new CircleGeometry(1.65, 40),
|
|
240
|
+
new MeshBasicMaterial({ color: 0x111827, transparent: true, opacity: 0.16, depthWrite: false }),
|
|
241
|
+
);
|
|
242
|
+
shadow.position.set(0, -1.33, -0.65);
|
|
243
|
+
shadow.scale.set(1.4, 0.34, 1);
|
|
244
|
+
root.add(shadow);
|
|
245
|
+
|
|
246
|
+
const body = new Mesh(new SphereGeometry(1, 36, 24), shellMaterial);
|
|
247
|
+
body.position.set(0, 0.02, 0);
|
|
248
|
+
body.scale.set(1.58, 0.92, 0.68);
|
|
249
|
+
root.add(body);
|
|
250
|
+
|
|
251
|
+
const lowerShell = new Mesh(new SphereGeometry(0.92, 28, 20), accentMaterial);
|
|
252
|
+
lowerShell.position.set(0, -0.48, 0.22);
|
|
253
|
+
lowerShell.scale.set(1.28, 0.42, 0.56);
|
|
254
|
+
root.add(lowerShell);
|
|
255
|
+
|
|
256
|
+
const dominantClaw = addClaw(root, -1, shellMaterial, accentMaterial);
|
|
257
|
+
addClaw(root, 1, shellMaterial, accentMaterial);
|
|
258
|
+
const eyes = addEyes(root, shellMaterial, eyeMaterial);
|
|
259
|
+
const legs = addLegs(root, legMaterial);
|
|
260
|
+
|
|
261
|
+
scene.add(new AmbientLight(0xfff7ed, 1.65));
|
|
262
|
+
scene.add(new HemisphereLight(0xfff7ed, 0x172033, 2.15));
|
|
263
|
+
const keyLight = new DirectionalLight(0xffffff, 3.6);
|
|
264
|
+
keyLight.position.set(3.5, 4.5, 6);
|
|
265
|
+
scene.add(keyLight);
|
|
266
|
+
const fillLight = new DirectionalLight(0xfbbf24, 1.35);
|
|
267
|
+
fillLight.position.set(-4, 1.5, 4);
|
|
268
|
+
scene.add(fillLight);
|
|
269
|
+
const rimLight = new PointLight(0xf59e0b, 1.8, 12, 2);
|
|
270
|
+
rimLight.position.set(0, 1.8, 4.5);
|
|
271
|
+
scene.add(rimLight);
|
|
272
|
+
|
|
273
|
+
return { bodyMaterial: shellMaterial, dominantClaw, eyes, legs, rimLight, root };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function moodColor(mood: InspectorPetMood): number {
|
|
277
|
+
switch (mood) {
|
|
278
|
+
case "active":
|
|
279
|
+
return 0x22d3ee;
|
|
280
|
+
case "attention":
|
|
281
|
+
return 0xef4444;
|
|
282
|
+
case "idle":
|
|
283
|
+
return 0xf59e0b;
|
|
284
|
+
case "sleeping":
|
|
285
|
+
return 0x94a3b8;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function isDisposableMesh(object: Object3D): object is Mesh<BufferGeometry, Material | Material[]> {
|
|
290
|
+
return object instanceof Mesh;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function disposeScene(scene: Scene): void {
|
|
294
|
+
const materials = new Set<Material>();
|
|
295
|
+
scene.traverse((object: Object3D) => {
|
|
296
|
+
if (!isDisposableMesh(object)) return;
|
|
297
|
+
object.geometry.dispose();
|
|
298
|
+
const material = object.material;
|
|
299
|
+
if (Array.isArray(material)) {
|
|
300
|
+
for (const item of material) materials.add(item);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
materials.add(material);
|
|
304
|
+
});
|
|
305
|
+
for (const material of materials) material.dispose();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function InspectorPetCrab3D({
|
|
309
|
+
mood,
|
|
310
|
+
moving,
|
|
311
|
+
reduceMotion,
|
|
312
|
+
}: InspectorPetCrab3DProps): JSX.Element {
|
|
313
|
+
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
314
|
+
const moodRef = useRef(mood);
|
|
315
|
+
const movingRef = useRef(moving);
|
|
316
|
+
const reduceMotionRef = useRef(reduceMotion);
|
|
317
|
+
const [renderFailed, setRenderFailed] = useState(false);
|
|
318
|
+
|
|
319
|
+
useEffect(() => {
|
|
320
|
+
moodRef.current = mood;
|
|
321
|
+
}, [mood]);
|
|
322
|
+
|
|
323
|
+
useEffect(() => {
|
|
324
|
+
movingRef.current = moving;
|
|
325
|
+
}, [moving]);
|
|
326
|
+
|
|
327
|
+
useEffect(() => {
|
|
328
|
+
reduceMotionRef.current = reduceMotion;
|
|
329
|
+
}, [reduceMotion]);
|
|
330
|
+
|
|
331
|
+
useEffect(() => {
|
|
332
|
+
const canvas = canvasRef.current;
|
|
333
|
+
if (canvas === null) return undefined;
|
|
334
|
+
|
|
335
|
+
let renderer: WebGLRenderer;
|
|
336
|
+
try {
|
|
337
|
+
renderer = new WebGLRenderer({
|
|
338
|
+
alpha: true,
|
|
339
|
+
antialias: true,
|
|
340
|
+
canvas,
|
|
341
|
+
powerPreference: "low-power",
|
|
342
|
+
preserveDrawingBuffer: true,
|
|
343
|
+
});
|
|
344
|
+
} catch {
|
|
345
|
+
setRenderFailed(true);
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
renderer.setClearColor(0x000000, 0);
|
|
350
|
+
renderer.outputColorSpace = SRGBColorSpace;
|
|
351
|
+
renderer.toneMapping = ACESFilmicToneMapping;
|
|
352
|
+
renderer.toneMappingExposure = 1.18;
|
|
353
|
+
|
|
354
|
+
const scene = new Scene();
|
|
355
|
+
const camera = new OrthographicCamera(-3.65, 3.65, 3.65, -3.65, 0.1, 20);
|
|
356
|
+
camera.position.set(0, 0.05, 8);
|
|
357
|
+
camera.lookAt(0, 0, 0);
|
|
358
|
+
const parts = createCrabScene(scene);
|
|
359
|
+
const startedAt = window.performance.now();
|
|
360
|
+
let lastFrameAt = 0;
|
|
361
|
+
|
|
362
|
+
const renderFrame = (timestamp: number): void => {
|
|
363
|
+
if (timestamp - lastFrameAt < 32) return;
|
|
364
|
+
lastFrameAt = timestamp;
|
|
365
|
+
const elapsed = (timestamp - startedAt) / 1000;
|
|
366
|
+
const motionAllowed = !reduceMotionRef.current;
|
|
367
|
+
const gait = movingRef.current ? 1 : moodRef.current === "active" ? 0.42 : 0;
|
|
368
|
+
const idleMotion = motionAllowed ? Math.sin(elapsed * 0.85) : 0;
|
|
369
|
+
const stepMotion = motionAllowed ? Math.sin(elapsed * 3.4) : 0;
|
|
370
|
+
const clawGrip = motionAllowed ? dominantClawGrip(elapsed) : 0;
|
|
371
|
+
|
|
372
|
+
parts.root.position.y = idleMotion * 0.035 + Math.abs(stepMotion) * 0.055 * gait;
|
|
373
|
+
parts.root.rotation.y = -0.08 + idleMotion * 0.055;
|
|
374
|
+
parts.root.rotation.z = stepMotion * 0.028 * gait;
|
|
375
|
+
parts.dominantClaw.group.rotation.z = -clawGrip * 0.035;
|
|
376
|
+
for (const pincer of parts.dominantClaw.pincers) {
|
|
377
|
+
pincer.mesh.position.y =
|
|
378
|
+
pincer.restY - pincer.direction * parts.dominantClaw.scale * 0.16 * clawGrip;
|
|
379
|
+
pincer.mesh.rotation.z = pincer.restRotationZ * (1 - clawGrip * 0.72);
|
|
380
|
+
}
|
|
381
|
+
for (const leg of parts.legs) {
|
|
382
|
+
leg.group.rotation.z =
|
|
383
|
+
motionAllowed && gait > 0
|
|
384
|
+
? Math.sin(elapsed * 4.25 + leg.phase) * 0.2 * leg.side * gait
|
|
385
|
+
: 0;
|
|
386
|
+
leg.group.rotation.x = motionAllowed && gait > 0 ? stepMotion * 0.045 * gait : 0;
|
|
387
|
+
}
|
|
388
|
+
for (const eye of parts.eyes) {
|
|
389
|
+
const gaze = motionAllowed ? Math.sin(elapsed * 0.72 + eye.phase) : 0;
|
|
390
|
+
const lift = motionAllowed ? Math.cos(elapsed * 0.9 + eye.phase) : 0;
|
|
391
|
+
eye.group.rotation.z = gaze * 0.075;
|
|
392
|
+
eye.group.rotation.x = lift * 0.025;
|
|
393
|
+
eye.pupil.position.set(
|
|
394
|
+
eye.pupilRest.x + gaze * 0.055,
|
|
395
|
+
eye.pupilRest.y + lift * 0.025,
|
|
396
|
+
eye.pupilRest.z,
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const color = moodColor(moodRef.current);
|
|
401
|
+
parts.rimLight.color.setHex(color);
|
|
402
|
+
parts.rimLight.intensity = moodRef.current === "attention" ? 3.2 : 1.8;
|
|
403
|
+
parts.bodyMaterial.emissive.setHex(color);
|
|
404
|
+
parts.bodyMaterial.emissiveIntensity = moodRef.current === "active" ? 0.12 : 0.035;
|
|
405
|
+
renderer.render(scene, camera);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const resize = (): void => {
|
|
409
|
+
const width = Math.max(canvas.clientWidth, 1);
|
|
410
|
+
const height = Math.max(canvas.clientHeight, 1);
|
|
411
|
+
renderer.setDrawingBufferSize(width, height, Math.min(window.devicePixelRatio, 2));
|
|
412
|
+
renderer.render(scene, camera);
|
|
413
|
+
};
|
|
414
|
+
const resizeObserver =
|
|
415
|
+
typeof ResizeObserver === "undefined" ? null : new ResizeObserver(resize);
|
|
416
|
+
if (resizeObserver === null) {
|
|
417
|
+
window.addEventListener("resize", resize);
|
|
418
|
+
} else {
|
|
419
|
+
resizeObserver.observe(canvas);
|
|
420
|
+
}
|
|
421
|
+
resize();
|
|
422
|
+
|
|
423
|
+
const handleContextLost = (event: Event): void => {
|
|
424
|
+
event.preventDefault();
|
|
425
|
+
setRenderFailed(true);
|
|
426
|
+
};
|
|
427
|
+
canvas.addEventListener("webglcontextlost", handleContextLost);
|
|
428
|
+
renderer.setAnimationLoop(renderFrame);
|
|
429
|
+
|
|
430
|
+
return () => {
|
|
431
|
+
renderer.setAnimationLoop(null);
|
|
432
|
+
if (resizeObserver === null) {
|
|
433
|
+
window.removeEventListener("resize", resize);
|
|
434
|
+
} else {
|
|
435
|
+
resizeObserver.disconnect();
|
|
436
|
+
}
|
|
437
|
+
canvas.removeEventListener("webglcontextlost", handleContextLost);
|
|
438
|
+
disposeScene(scene);
|
|
439
|
+
renderer.dispose();
|
|
440
|
+
};
|
|
441
|
+
}, []);
|
|
442
|
+
|
|
443
|
+
return (
|
|
444
|
+
<span className="relative flex size-24 items-center justify-center" aria-hidden="true">
|
|
445
|
+
<canvas
|
|
446
|
+
ref={canvasRef}
|
|
447
|
+
className={renderFailed ? "hidden" : "block size-full bg-transparent"}
|
|
448
|
+
data-inspector-pet-canvas="true"
|
|
449
|
+
/>
|
|
450
|
+
{renderFailed && (
|
|
451
|
+
<CrabLogo className="size-22 text-amber-500 drop-shadow-[0_0_18px_rgba(245,158,11,0.28)]" />
|
|
452
|
+
)}
|
|
453
|
+
</span>
|
|
454
|
+
);
|
|
455
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { CapturedLog } from "../../contracts";
|
|
2
|
+
|
|
3
|
+
export type InspectorPetPosition = {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type InspectorPetViewport = {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
scale?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type InspectorPetEdge = "left" | "right" | "top" | "bottom";
|
|
15
|
+
export type InspectorPetMood = "active" | "attention" | "idle" | "sleeping";
|
|
16
|
+
|
|
17
|
+
export type InspectorPetStatus = {
|
|
18
|
+
mood: InspectorPetMood;
|
|
19
|
+
label: string;
|
|
20
|
+
pendingCount: number;
|
|
21
|
+
capturedCount: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const INSPECTOR_PET_SIZE = 112;
|
|
25
|
+
export const INSPECTOR_PET_MARGIN = 14;
|
|
26
|
+
export const INSPECTOR_PET_EDGE_GAP = 20;
|
|
27
|
+
export const INSPECTOR_PET_MIN_STEP = 36;
|
|
28
|
+
export const INSPECTOR_PET_MAX_STEP = 92;
|
|
29
|
+
export const INSPECTOR_PET_SLEEP_AFTER_MS = 45_000;
|
|
30
|
+
|
|
31
|
+
const INSPECTOR_PET_PANEL_WIDTH = 192;
|
|
32
|
+
const INSPECTOR_PET_PANEL_HEIGHT = 68;
|
|
33
|
+
const INSPECTOR_PET_PANEL_GAP = 10;
|
|
34
|
+
const INSPECTOR_PET_VERTICAL_SAFE_MARGIN = 78;
|
|
35
|
+
|
|
36
|
+
function viewportScale(viewport: InspectorPetViewport): number {
|
|
37
|
+
const scale = viewport.scale ?? 1;
|
|
38
|
+
return Number.isFinite(scale) && scale > 0 ? scale : 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function scaledMetric(value: number, viewport: InspectorPetViewport): number {
|
|
42
|
+
return value * viewportScale(viewport);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function clampUnit(value: number): number {
|
|
46
|
+
return Math.min(Math.max(value, 0), 1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function maximumPetX(viewport: InspectorPetViewport): number {
|
|
50
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
51
|
+
return Math.max(edgeGap, viewport.width - scaledMetric(INSPECTOR_PET_SIZE, viewport) - edgeGap);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function maximumPetY(viewport: InspectorPetViewport): number {
|
|
55
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
56
|
+
return Math.max(edgeGap, viewport.height - scaledMetric(INSPECTOR_PET_SIZE, viewport) - edgeGap);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function clampInspectorPetPosition(
|
|
60
|
+
position: InspectorPetPosition,
|
|
61
|
+
viewport: InspectorPetViewport,
|
|
62
|
+
): InspectorPetPosition {
|
|
63
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
64
|
+
return {
|
|
65
|
+
x: Math.min(Math.max(position.x, edgeGap), maximumPetX(viewport)),
|
|
66
|
+
y: Math.min(Math.max(position.y, edgeGap), maximumPetY(viewport)),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function nearestInspectorPetEdge(
|
|
71
|
+
position: InspectorPetPosition,
|
|
72
|
+
viewport: InspectorPetViewport,
|
|
73
|
+
): InspectorPetEdge {
|
|
74
|
+
const clamped = clampInspectorPetPosition(position, viewport);
|
|
75
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
76
|
+
const distances: { edge: InspectorPetEdge; distance: number }[] = [
|
|
77
|
+
{ edge: "left", distance: clamped.x - edgeGap },
|
|
78
|
+
{ edge: "right", distance: maximumPetX(viewport) - clamped.x },
|
|
79
|
+
{ edge: "top", distance: clamped.y - edgeGap },
|
|
80
|
+
{ edge: "bottom", distance: maximumPetY(viewport) - clamped.y },
|
|
81
|
+
];
|
|
82
|
+
return distances.reduce((best, current) => (current.distance < best.distance ? current : best))
|
|
83
|
+
.edge;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function snapInspectorPetToEdge(
|
|
87
|
+
position: InspectorPetPosition,
|
|
88
|
+
viewport: InspectorPetViewport,
|
|
89
|
+
): InspectorPetPosition {
|
|
90
|
+
const clamped = clampInspectorPetPosition(position, viewport);
|
|
91
|
+
const edge = nearestInspectorPetEdge(clamped, viewport);
|
|
92
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
93
|
+
|
|
94
|
+
switch (edge) {
|
|
95
|
+
case "left":
|
|
96
|
+
return { x: edgeGap, y: clamped.y };
|
|
97
|
+
case "right":
|
|
98
|
+
return { x: maximumPetX(viewport), y: clamped.y };
|
|
99
|
+
case "top":
|
|
100
|
+
return { x: clamped.x, y: edgeGap };
|
|
101
|
+
case "bottom":
|
|
102
|
+
return { x: clamped.x, y: maximumPetY(viewport) };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function randomInspectorPetEdgePosition(
|
|
107
|
+
viewport: InspectorPetViewport,
|
|
108
|
+
positionSample: number,
|
|
109
|
+
): InspectorPetPosition {
|
|
110
|
+
const maxX = maximumPetX(viewport);
|
|
111
|
+
const maxY = maximumPetY(viewport);
|
|
112
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
113
|
+
return {
|
|
114
|
+
x: edgeGap + clampUnit(positionSample) * (maxX - edgeGap),
|
|
115
|
+
y: maxY,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function nextInspectorPetWalkingPosition(
|
|
120
|
+
position: InspectorPetPosition,
|
|
121
|
+
viewport: InspectorPetViewport,
|
|
122
|
+
stepSample: number,
|
|
123
|
+
directionSample: number,
|
|
124
|
+
): InspectorPetPosition {
|
|
125
|
+
const clamped = snapInspectorPetToEdge(position, viewport);
|
|
126
|
+
const step =
|
|
127
|
+
scaledMetric(INSPECTOR_PET_MIN_STEP, viewport) +
|
|
128
|
+
clampUnit(stepSample) * scaledMetric(INSPECTOR_PET_MAX_STEP - INSPECTOR_PET_MIN_STEP, viewport);
|
|
129
|
+
const direction = directionSample >= 0.5 ? 1 : -1;
|
|
130
|
+
const edge = nearestInspectorPetEdge(clamped, viewport);
|
|
131
|
+
const maxX = maximumPetX(viewport);
|
|
132
|
+
const maxY = maximumPetY(viewport);
|
|
133
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
134
|
+
const minimumSafeY = Math.min(scaledMetric(INSPECTOR_PET_VERTICAL_SAFE_MARGIN, viewport), maxY);
|
|
135
|
+
|
|
136
|
+
switch (edge) {
|
|
137
|
+
case "left":
|
|
138
|
+
return {
|
|
139
|
+
x: edgeGap,
|
|
140
|
+
y: Math.min(Math.max(clamped.y + step * direction, minimumSafeY), maxY),
|
|
141
|
+
};
|
|
142
|
+
case "right":
|
|
143
|
+
return {
|
|
144
|
+
x: maxX,
|
|
145
|
+
y: Math.min(Math.max(clamped.y + step * direction, minimumSafeY), maxY),
|
|
146
|
+
};
|
|
147
|
+
case "top":
|
|
148
|
+
return {
|
|
149
|
+
x: Math.min(Math.max(clamped.x + step * direction, edgeGap), maxX),
|
|
150
|
+
y: edgeGap,
|
|
151
|
+
};
|
|
152
|
+
case "bottom":
|
|
153
|
+
return {
|
|
154
|
+
x: Math.min(Math.max(clamped.x + step * direction, edgeGap), maxX),
|
|
155
|
+
y: maxY,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function inspectorPetPanelPosition(
|
|
161
|
+
position: InspectorPetPosition,
|
|
162
|
+
viewport: InspectorPetViewport,
|
|
163
|
+
): InspectorPetPosition {
|
|
164
|
+
const edge = nearestInspectorPetEdge(position, viewport);
|
|
165
|
+
const petSize = scaledMetric(INSPECTOR_PET_SIZE, viewport);
|
|
166
|
+
const panelWidth = scaledMetric(INSPECTOR_PET_PANEL_WIDTH, viewport);
|
|
167
|
+
const panelHeight = scaledMetric(INSPECTOR_PET_PANEL_HEIGHT, viewport);
|
|
168
|
+
const panelGap = scaledMetric(INSPECTOR_PET_PANEL_GAP, viewport);
|
|
169
|
+
const margin = scaledMetric(INSPECTOR_PET_MARGIN, viewport);
|
|
170
|
+
let x = position.x + petSize / 2 - panelWidth / 2;
|
|
171
|
+
let y = position.y + petSize / 2 - panelHeight / 2;
|
|
172
|
+
|
|
173
|
+
switch (edge) {
|
|
174
|
+
case "left":
|
|
175
|
+
x = position.x + petSize + panelGap;
|
|
176
|
+
break;
|
|
177
|
+
case "right":
|
|
178
|
+
x = position.x - panelWidth - panelGap;
|
|
179
|
+
break;
|
|
180
|
+
case "top":
|
|
181
|
+
y = position.y + petSize + panelGap;
|
|
182
|
+
break;
|
|
183
|
+
case "bottom":
|
|
184
|
+
y = position.y - panelHeight - panelGap;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
x: Math.min(Math.max(x, margin), Math.max(margin, viewport.width - panelWidth - margin)),
|
|
190
|
+
y: Math.min(Math.max(y, margin), Math.max(margin, viewport.height - panelHeight - margin)),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function latestCapturedLog(logs: readonly CapturedLog[]): CapturedLog | null {
|
|
195
|
+
let latest: CapturedLog | null = null;
|
|
196
|
+
for (const log of logs) {
|
|
197
|
+
if (latest === null || log.id > latest.id) latest = log;
|
|
198
|
+
}
|
|
199
|
+
return latest;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function logNeedsAttention(log: CapturedLog): boolean {
|
|
203
|
+
const hasHttpError = log.responseStatus !== null && log.responseStatus >= 400;
|
|
204
|
+
const hasStreamError = log.error !== null && log.error !== undefined && log.error !== "";
|
|
205
|
+
return hasHttpError || hasStreamError;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function resolveInspectorPetStatus(
|
|
209
|
+
logs: readonly CapturedLog[],
|
|
210
|
+
nowMs: number,
|
|
211
|
+
): InspectorPetStatus {
|
|
212
|
+
const pendingCount = logs.filter((log) => log.responseStatus === null).length;
|
|
213
|
+
const capturedCount = logs.length;
|
|
214
|
+
if (pendingCount > 0) {
|
|
215
|
+
return {
|
|
216
|
+
mood: "active",
|
|
217
|
+
label: `${String(pendingCount)} request${pendingCount === 1 ? "" : "s"} in flight`,
|
|
218
|
+
pendingCount,
|
|
219
|
+
capturedCount,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const latest = latestCapturedLog(logs);
|
|
224
|
+
if (latest !== null && logNeedsAttention(latest)) {
|
|
225
|
+
return {
|
|
226
|
+
mood: "attention",
|
|
227
|
+
label: "Latest request needs attention",
|
|
228
|
+
pendingCount,
|
|
229
|
+
capturedCount,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (latest === null) {
|
|
234
|
+
return {
|
|
235
|
+
mood: "idle",
|
|
236
|
+
label: "Waiting for traffic",
|
|
237
|
+
pendingCount,
|
|
238
|
+
capturedCount,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const latestTimestamp = Date.parse(latest.timestamp);
|
|
243
|
+
if (Number.isFinite(latestTimestamp) && nowMs - latestTimestamp >= INSPECTOR_PET_SLEEP_AFTER_MS) {
|
|
244
|
+
return {
|
|
245
|
+
mood: "sleeping",
|
|
246
|
+
label: "All quiet",
|
|
247
|
+
pendingCount,
|
|
248
|
+
capturedCount,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
mood: "idle",
|
|
254
|
+
label: "Watching the session",
|
|
255
|
+
pendingCount,
|
|
256
|
+
capturedCount,
|
|
257
|
+
};
|
|
258
|
+
}
|