@tonyclaw/agent-inspector 3.0.28 → 3.0.30
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/cli.js +791 -191
- package/.output/nitro.json +1 -1
- package/.output/public/assets/CompareDrawer-B6cXJohL.js +1 -0
- package/.output/public/assets/InspectorPet-mAzeGmEE.js +4108 -0
- package/.output/public/assets/ProxyViewerContainer-CkFWv_Nm.js +126 -0
- package/.output/public/assets/{ReplayDialog-CZMApaF4.js → ReplayDialog-DodiTL6E.js} +1 -1
- package/.output/public/assets/{RequestAnatomy-DNWccR7O.js → RequestAnatomy-B3IauToI.js} +1 -1
- package/.output/public/assets/ResponseView-Hn-5ordK.js +3 -0
- package/.output/public/assets/StreamingChunkSequence-vLDOVQM_.js +1 -0
- package/.output/public/assets/_sessionId-BFH4TOaI.js +1 -0
- package/.output/public/assets/{_sessionId-DRfvuE2k.js → _sessionId-Cj_HIFZx.js} +1 -1
- package/.output/public/assets/{index-D4HkS7Ct.js → index-Bmj2lcWE.js} +1 -1
- package/.output/public/assets/index-CgJj-HBC.css +1 -0
- package/.output/public/assets/index-Ch7uqnCT.js +1 -0
- package/.output/public/assets/index-DkDdKvLl.js +76 -0
- package/.output/public/assets/{index-B3aAuqWq.js → index-ZlhqCrSg.js} +6 -6
- package/.output/public/assets/{json-viewer-wuJSKaed.js → json-viewer-BdrnVQu-.js} +1 -1
- package/.output/public/assets/jszip.min-CS_nt_o1.js +2 -0
- package/.output/public/assets/qwen-mMn3f5ul.webp +0 -0
- package/.output/server/_libs/jszip.mjs +35 -9
- package/.output/server/_libs/lucide-react.mjs +86 -86
- package/.output/server/_libs/radix-ui__react-dialog.mjs +3 -3
- package/.output/server/_libs/tanstack__react-router.mjs +1 -1
- package/.output/server/{_sessionId-BJTNiP_O.mjs → _sessionId-C5S3pGZd.mjs} +15 -15
- package/.output/server/_sessionId-g6D69lKq.mjs +81 -0
- package/.output/server/_ssr/{CompareDrawer-BMRH3N97.mjs → CompareDrawer-CqUmGHal.mjs} +138 -103
- package/.output/server/_ssr/InspectorPet-DI0UJd01.mjs +925 -0
- package/.output/server/_ssr/{ProxyViewerContainer-AFwcHAIR.mjs → ProxyViewerContainer-CvsUmbJ3.mjs} +1216 -1659
- package/.output/server/_ssr/{ReplayDialog-CbWvRHiN.mjs → ReplayDialog-DS48dpFG.mjs} +18 -18
- package/.output/server/_ssr/{RequestAnatomy-C4kcPyqN.mjs → RequestAnatomy-DxYVQU1C.mjs} +58 -58
- package/.output/server/_ssr/{ResponseView-D8VYt-gZ.mjs → ResponseView-BLXW73eq.mjs} +60 -60
- package/.output/server/_ssr/{StreamingChunkSequence-BUUo6vU0.mjs → StreamingChunkSequence-DD0iFuy0.mjs} +16 -16
- package/.output/server/_ssr/{index-DTwMEEXO.mjs → index-B10LIaK0.mjs} +15 -15
- package/.output/server/_ssr/index-RHVJnU2p.mjs +81 -0
- package/.output/server/_ssr/index.mjs +2 -2
- package/.output/server/_ssr/{json-viewer-BqF1pSQD.mjs → json-viewer-LDu2XBaK.mjs} +58 -58
- package/.output/server/_ssr/{router-C8BOns7y.mjs → router-GKvrwifJ.mjs} +9005 -6488
- package/.output/server/_tanstack-start-manifest_v-Df2n4mbT.mjs +4 -0
- package/.output/server/index.mjs +105 -77
- package/.output/workers/logFinalizer.worker.js +16908 -0
- package/.output/workers/sessionWorkerEntry.js +16904 -0
- package/README.md +21 -5
- package/package.json +6 -2
- package/src/assets/logos/qwen.webp +0 -0
- package/src/cli.ts +85 -10
- package/src/components/OnboardingBanner.tsx +41 -21
- package/src/components/ProxyViewer.tsx +198 -269
- package/src/components/ProxyViewerContainer.tsx +128 -17
- package/src/components/clients/ClientLogo.tsx +9 -6
- package/src/components/ecosystem/AgentLabDialog.tsx +166 -19
- package/src/components/errors/SafeErrorBoundary.tsx +201 -0
- package/src/components/pi-agent/PiAgentPanel.tsx +4 -1
- package/src/components/providers/ImportWizardDialog.tsx +18 -42
- package/src/components/providers/ProviderLogo.tsx +1 -1
- package/src/components/providers/ProvidersPanel.tsx +8 -5
- package/src/components/providers/SettingsDialog.tsx +34 -11
- package/src/components/proxy-viewer/ApplicationBar.tsx +63 -0
- package/src/components/proxy-viewer/CompareDrawer.tsx +92 -49
- package/src/components/proxy-viewer/ConversationGroupList.tsx +49 -34
- package/src/components/proxy-viewer/ConversationHeader.tsx +22 -18
- package/src/components/proxy-viewer/LiveConnectionStatus.tsx +186 -0
- package/src/components/proxy-viewer/LogEntry.tsx +283 -275
- package/src/components/proxy-viewer/RawExportWarning.tsx +77 -0
- package/src/components/proxy-viewer/SessionLoadProgressBar.tsx +61 -0
- package/src/components/proxy-viewer/ThreadConnector.tsx +16 -1
- package/src/components/proxy-viewer/TurnGroup.tsx +13 -2
- package/src/components/proxy-viewer/accessibility.ts +8 -0
- package/src/components/proxy-viewer/lazy.ts +4 -0
- package/src/components/proxy-viewer/liveConnectionState.ts +158 -0
- package/src/components/proxy-viewer/proxyViewerLogic.ts +10 -0
- package/src/components/proxy-viewer/viewerState.ts +2 -6
- package/src/components/ui/select.tsx +1 -1
- package/src/components/ui/tabs.tsx +3 -3
- package/src/components/ui/transient-toast.tsx +1 -1
- package/src/lib/apiClient.ts +17 -2
- package/src/lib/ecosystemContract.ts +34 -0
- package/src/lib/export-logs.ts +1 -1
- package/src/lib/providerContract.ts +70 -4
- package/src/lib/providerImportContract.ts +27 -0
- package/src/lib/providerModelMetadata.ts +16 -7
- package/src/lib/resourceLimits.ts +152 -0
- package/src/lib/safeDiagnostic.ts +38 -0
- package/src/lib/useProviders.ts +4 -4
- package/src/lib/utils.ts +5 -1
- package/src/mcp/server.ts +39 -6
- package/src/mcp/toolHandlers.ts +131 -4
- package/src/proxy/chunkStorage.ts +20 -6
- package/src/proxy/config.ts +20 -6
- package/src/proxy/dataDir.ts +3 -0
- package/src/proxy/ecosystemExecutionConfirmation.ts +114 -0
- package/src/proxy/ecosystemExecutionRoute.ts +116 -0
- package/src/proxy/ecosystemTasks.ts +48 -0
- package/src/proxy/evidenceExporter.ts +23 -9
- package/src/proxy/groupEvidenceExporter.ts +26 -5
- package/src/proxy/groupStore.ts +13 -3
- package/src/proxy/handler.ts +103 -20
- package/src/proxy/identityProxy.ts +333 -14
- package/src/proxy/logFinalizer.ts +73 -6
- package/src/proxy/logImportUpload.ts +128 -0
- package/src/proxy/logImporter.ts +321 -70
- package/src/proxy/logIndex.ts +16 -6
- package/src/proxy/logger.ts +294 -41
- package/src/proxy/privateDataPath.ts +183 -0
- package/src/proxy/providerScanStore.ts +87 -0
- package/src/proxy/providerSecretStore.ts +58 -19
- package/src/proxy/providers.ts +175 -58
- package/src/proxy/rawStreamCapture.ts +66 -5
- package/src/proxy/runStore.ts +13 -3
- package/src/proxy/runtimeAdmission.ts +52 -0
- package/src/proxy/runtimeHealth.ts +206 -0
- package/src/proxy/runtimeShutdown.ts +75 -0
- package/src/proxy/sessionArchive.ts +15 -2
- package/src/proxy/sessionProcess.ts +19 -0
- package/src/proxy/sessionRuntime.ts +7 -0
- package/src/proxy/shutdownCoordinator.ts +90 -0
- package/src/proxy/sqliteLogIndex.ts +18 -2
- package/src/proxy/store.ts +18 -2
- package/src/routes/__root.tsx +18 -1
- package/src/routes/api/alerts.summary.ts +12 -8
- package/src/routes/api/alerts.ts +27 -9
- package/src/routes/api/ecosystem.packages.$packageId.help.ts +3 -8
- package/src/routes/api/ecosystem.packages.$packageId.install.ts +3 -8
- package/src/routes/api/ecosystem.packages.$packageId.runner-presets.ts +3 -11
- package/src/routes/api/ecosystem.packages.$packageId.upgrade.ts +3 -8
- package/src/routes/api/ecosystem.recipes.$recipeId.run.ts +3 -8
- package/src/routes/api/health.ts +9 -2
- package/src/routes/api/knowledge.project-context.ts +11 -0
- package/src/routes/api/knowledge.search.ts +33 -2
- package/src/routes/api/logs.$id.body.ts +16 -2
- package/src/routes/api/logs.import.ts +7 -18
- package/src/routes/api/logs.stream.ts +147 -69
- package/src/routes/api/logs.ts +55 -14
- package/src/routes/api/providers.$providerId.model-metadata.ts +22 -4
- package/src/routes/api/providers.$providerId.ts +37 -6
- package/src/routes/api/providers.export.ts +34 -16
- package/src/routes/api/providers.import.ts +42 -8
- package/src/routes/api/providers.scan.ts +13 -8
- package/src/routes/api/providers.ts +36 -5
- package/src/routes/api/runs.ts +12 -12
- package/src/routes/api/sessions.ts +15 -8
- package/src/routes/index.tsx +6 -0
- package/src/routes/livez.ts +13 -0
- package/src/routes/readyz.ts +18 -0
- package/src/routes/session/$sessionId.tsx +6 -0
- package/styles/globals.css +19 -3
- package/.output/public/assets/CompareDrawer-TghZr5t1.js +0 -1
- package/.output/public/assets/ProxyViewerContainer-fShBAZjj.js +0 -4234
- package/.output/public/assets/ResponseView-d25MdFhY.js +0 -3
- package/.output/public/assets/StreamingChunkSequence-DIFZEnWe.js +0 -1
- package/.output/public/assets/index-BsxAGqMA.css +0 -1
- package/.output/public/assets/index-DzARL2Fi.js +0 -76
- package/.output/public/assets/qwen-CONDcHqt.png +0 -0
- package/.output/server/_tanstack-start-manifest_v-BBf2nRhb.mjs +0 -4
- package/src/assets/logos/mcp.png +0 -0
- package/src/assets/logos/qwen.png +0 -0
- package/src/components/ui/mcp-logo.tsx +0 -20
|
@@ -0,0 +1,925 @@
|
|
|
1
|
+
import { r as reactExports, j as jsxRuntimeExports } from "../_libs/react.mjs";
|
|
2
|
+
import { r as reactDomExports } from "../_libs/react-dom.mjs";
|
|
3
|
+
import { m as cn, af as CrabLogo } from "./router-GKvrwifJ.mjs";
|
|
4
|
+
import { W as WebGLRenderer, S as SRGBColorSpace, A as ACESFilmicToneMapping, a as Scene, O as OrthographicCamera, M as MeshPhysicalMaterial, C as Color, G as Group, b as Mesh, c as CircleGeometry, d as MeshBasicMaterial, e as SphereGeometry, f as AmbientLight, H as HemisphereLight, D as DirectionalLight, P as PointLight, V as Vector3, g as CylinderGeometry } from "../_libs/three.mjs";
|
|
5
|
+
import "node:crypto";
|
|
6
|
+
import "node:path";
|
|
7
|
+
import "node:fs";
|
|
8
|
+
import "node:child_process";
|
|
9
|
+
import "node:buffer";
|
|
10
|
+
import "node:url";
|
|
11
|
+
import "crypto";
|
|
12
|
+
import "node:util";
|
|
13
|
+
import "node:net";
|
|
14
|
+
import "../_libs/modelcontextprotocol__server.mjs";
|
|
15
|
+
import "../_libs/jszip.mjs";
|
|
16
|
+
import "node:os";
|
|
17
|
+
import { aG as Heart, aH as Pause, aI as Play } from "../_libs/lucide-react.mjs";
|
|
18
|
+
import "util";
|
|
19
|
+
import "async_hooks";
|
|
20
|
+
import "stream";
|
|
21
|
+
import "../_libs/tanstack__react-router.mjs";
|
|
22
|
+
import "../_libs/tanstack__router-core.mjs";
|
|
23
|
+
import "../_libs/cookie-es.mjs";
|
|
24
|
+
import "../_libs/seroval.mjs";
|
|
25
|
+
import "../_libs/seroval-plugins.mjs";
|
|
26
|
+
import "node:stream";
|
|
27
|
+
import "../_libs/tanstack__history.mjs";
|
|
28
|
+
import "node:stream/web";
|
|
29
|
+
import "../_libs/isbot.mjs";
|
|
30
|
+
import "../_libs/swr.mjs";
|
|
31
|
+
import "../_libs/use-sync-external-store.mjs";
|
|
32
|
+
import "../_libs/dequal.mjs";
|
|
33
|
+
import "../_libs/class-variance-authority.mjs";
|
|
34
|
+
import "../_libs/clsx.mjs";
|
|
35
|
+
import "../_libs/tailwind-merge.mjs";
|
|
36
|
+
import "node:fs/promises";
|
|
37
|
+
import "node:worker_threads";
|
|
38
|
+
import "node:readline";
|
|
39
|
+
import "../_libs/conf.mjs";
|
|
40
|
+
import "node:process";
|
|
41
|
+
import "node:assert";
|
|
42
|
+
import "../_libs/dot-prop.mjs";
|
|
43
|
+
import "../_libs/env-paths.mjs";
|
|
44
|
+
import "../_libs/atomically.mjs";
|
|
45
|
+
import "node:events";
|
|
46
|
+
import "../_libs/stubborn-fs.mjs";
|
|
47
|
+
import "../_libs/stubborn-utils.mjs";
|
|
48
|
+
import "../_libs/when-exit.mjs";
|
|
49
|
+
import "../_libs/ajv.mjs";
|
|
50
|
+
import "../_libs/fast-deep-equal.mjs";
|
|
51
|
+
import "../_libs/json-schema-traverse.mjs";
|
|
52
|
+
import "../_libs/fast-uri.mjs";
|
|
53
|
+
import "../_libs/ajv-formats.mjs";
|
|
54
|
+
import "../_libs/debounce-fn.mjs";
|
|
55
|
+
import "../_libs/mimic-function.mjs";
|
|
56
|
+
import "../_libs/semver.mjs";
|
|
57
|
+
import "../_libs/uint8array-extras.mjs";
|
|
58
|
+
import "node:dns/promises";
|
|
59
|
+
import "node:assert/strict";
|
|
60
|
+
import "../_libs/zod.mjs";
|
|
61
|
+
import "../_libs/readable-stream.mjs";
|
|
62
|
+
import "events";
|
|
63
|
+
import "node:string_decoder";
|
|
64
|
+
import "../_libs/process-nextick-args.mjs";
|
|
65
|
+
import "../_libs/isarray.mjs";
|
|
66
|
+
import "../_libs/safe-buffer.mjs";
|
|
67
|
+
import "buffer";
|
|
68
|
+
import "../_libs/core-util-is.mjs";
|
|
69
|
+
import "../_libs/inherits.mjs";
|
|
70
|
+
import "../_libs/util-deprecate.mjs";
|
|
71
|
+
import "../_libs/lie.mjs";
|
|
72
|
+
import "../_libs/immediate.mjs";
|
|
73
|
+
import "../_libs/setimmediate.mjs";
|
|
74
|
+
import "../_libs/pako.mjs";
|
|
75
|
+
const INSPECTOR_PET_SIZE = 112;
|
|
76
|
+
const INSPECTOR_PET_MARGIN = 14;
|
|
77
|
+
const INSPECTOR_PET_EDGE_GAP = 20;
|
|
78
|
+
const INSPECTOR_PET_MIN_STEP = 36;
|
|
79
|
+
const INSPECTOR_PET_MAX_STEP = 92;
|
|
80
|
+
const INSPECTOR_PET_SLEEP_AFTER_MS = 45e3;
|
|
81
|
+
const INSPECTOR_PET_PANEL_WIDTH = 192;
|
|
82
|
+
const INSPECTOR_PET_PANEL_HEIGHT = 68;
|
|
83
|
+
const INSPECTOR_PET_PANEL_GAP = 10;
|
|
84
|
+
const INSPECTOR_PET_VERTICAL_SAFE_MARGIN = 78;
|
|
85
|
+
function viewportScale(viewport) {
|
|
86
|
+
const scale = viewport.scale ?? 1;
|
|
87
|
+
return Number.isFinite(scale) && scale > 0 ? scale : 1;
|
|
88
|
+
}
|
|
89
|
+
function scaledMetric(value, viewport) {
|
|
90
|
+
return value * viewportScale(viewport);
|
|
91
|
+
}
|
|
92
|
+
function clampUnit(value) {
|
|
93
|
+
return Math.min(Math.max(value, 0), 1);
|
|
94
|
+
}
|
|
95
|
+
function maximumPetX(viewport) {
|
|
96
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
97
|
+
return Math.max(edgeGap, viewport.width - scaledMetric(INSPECTOR_PET_SIZE, viewport) - edgeGap);
|
|
98
|
+
}
|
|
99
|
+
function maximumPetY(viewport) {
|
|
100
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
101
|
+
return Math.max(edgeGap, viewport.height - scaledMetric(INSPECTOR_PET_SIZE, viewport) - edgeGap);
|
|
102
|
+
}
|
|
103
|
+
function clampInspectorPetPosition(position, viewport) {
|
|
104
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
105
|
+
return {
|
|
106
|
+
x: Math.min(Math.max(position.x, edgeGap), maximumPetX(viewport)),
|
|
107
|
+
y: Math.min(Math.max(position.y, edgeGap), maximumPetY(viewport))
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function nearestInspectorPetEdge(position, viewport) {
|
|
111
|
+
const clamped = clampInspectorPetPosition(position, viewport);
|
|
112
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
113
|
+
const distances = [
|
|
114
|
+
{ edge: "left", distance: clamped.x - edgeGap },
|
|
115
|
+
{ edge: "right", distance: maximumPetX(viewport) - clamped.x },
|
|
116
|
+
{ edge: "top", distance: clamped.y - edgeGap },
|
|
117
|
+
{ edge: "bottom", distance: maximumPetY(viewport) - clamped.y }
|
|
118
|
+
];
|
|
119
|
+
return distances.reduce((best, current) => current.distance < best.distance ? current : best).edge;
|
|
120
|
+
}
|
|
121
|
+
function snapInspectorPetToEdge(position, viewport) {
|
|
122
|
+
const clamped = clampInspectorPetPosition(position, viewport);
|
|
123
|
+
const edge = nearestInspectorPetEdge(clamped, viewport);
|
|
124
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
125
|
+
switch (edge) {
|
|
126
|
+
case "left":
|
|
127
|
+
return { x: edgeGap, y: clamped.y };
|
|
128
|
+
case "right":
|
|
129
|
+
return { x: maximumPetX(viewport), y: clamped.y };
|
|
130
|
+
case "top":
|
|
131
|
+
return { x: clamped.x, y: edgeGap };
|
|
132
|
+
case "bottom":
|
|
133
|
+
return { x: clamped.x, y: maximumPetY(viewport) };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function randomInspectorPetEdgePosition(viewport, positionSample) {
|
|
137
|
+
const maxX = maximumPetX(viewport);
|
|
138
|
+
const maxY = maximumPetY(viewport);
|
|
139
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
140
|
+
return {
|
|
141
|
+
x: edgeGap + clampUnit(positionSample) * (maxX - edgeGap),
|
|
142
|
+
y: maxY
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function nextInspectorPetWalkingPosition(position, viewport, stepSample, directionSample) {
|
|
146
|
+
const clamped = snapInspectorPetToEdge(position, viewport);
|
|
147
|
+
const step = scaledMetric(INSPECTOR_PET_MIN_STEP, viewport) + clampUnit(stepSample) * scaledMetric(INSPECTOR_PET_MAX_STEP - INSPECTOR_PET_MIN_STEP, viewport);
|
|
148
|
+
const direction = directionSample >= 0.5 ? 1 : -1;
|
|
149
|
+
const edge = nearestInspectorPetEdge(clamped, viewport);
|
|
150
|
+
const maxX = maximumPetX(viewport);
|
|
151
|
+
const maxY = maximumPetY(viewport);
|
|
152
|
+
const edgeGap = scaledMetric(INSPECTOR_PET_EDGE_GAP, viewport);
|
|
153
|
+
const minimumSafeY = Math.min(scaledMetric(INSPECTOR_PET_VERTICAL_SAFE_MARGIN, viewport), maxY);
|
|
154
|
+
switch (edge) {
|
|
155
|
+
case "left":
|
|
156
|
+
return {
|
|
157
|
+
x: edgeGap,
|
|
158
|
+
y: Math.min(Math.max(clamped.y + step * direction, minimumSafeY), maxY)
|
|
159
|
+
};
|
|
160
|
+
case "right":
|
|
161
|
+
return {
|
|
162
|
+
x: maxX,
|
|
163
|
+
y: Math.min(Math.max(clamped.y + step * direction, minimumSafeY), maxY)
|
|
164
|
+
};
|
|
165
|
+
case "top":
|
|
166
|
+
return {
|
|
167
|
+
x: Math.min(Math.max(clamped.x + step * direction, edgeGap), maxX),
|
|
168
|
+
y: edgeGap
|
|
169
|
+
};
|
|
170
|
+
case "bottom":
|
|
171
|
+
return {
|
|
172
|
+
x: Math.min(Math.max(clamped.x + step * direction, edgeGap), maxX),
|
|
173
|
+
y: maxY
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function inspectorPetPanelPosition(position, viewport) {
|
|
178
|
+
const edge = nearestInspectorPetEdge(position, viewport);
|
|
179
|
+
const petSize = scaledMetric(INSPECTOR_PET_SIZE, viewport);
|
|
180
|
+
const panelWidth = scaledMetric(INSPECTOR_PET_PANEL_WIDTH, viewport);
|
|
181
|
+
const panelHeight = scaledMetric(INSPECTOR_PET_PANEL_HEIGHT, viewport);
|
|
182
|
+
const panelGap = scaledMetric(INSPECTOR_PET_PANEL_GAP, viewport);
|
|
183
|
+
const margin = scaledMetric(INSPECTOR_PET_MARGIN, viewport);
|
|
184
|
+
let x = position.x + petSize / 2 - panelWidth / 2;
|
|
185
|
+
let y = position.y + petSize / 2 - panelHeight / 2;
|
|
186
|
+
switch (edge) {
|
|
187
|
+
case "left":
|
|
188
|
+
x = position.x + petSize + panelGap;
|
|
189
|
+
break;
|
|
190
|
+
case "right":
|
|
191
|
+
x = position.x - panelWidth - panelGap;
|
|
192
|
+
break;
|
|
193
|
+
case "top":
|
|
194
|
+
y = position.y + petSize + panelGap;
|
|
195
|
+
break;
|
|
196
|
+
case "bottom":
|
|
197
|
+
y = position.y - panelHeight - panelGap;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
x: Math.min(Math.max(x, margin), Math.max(margin, viewport.width - panelWidth - margin)),
|
|
202
|
+
y: Math.min(Math.max(y, margin), Math.max(margin, viewport.height - panelHeight - margin))
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function latestCapturedLog(logs) {
|
|
206
|
+
let latest = null;
|
|
207
|
+
for (const log of logs) {
|
|
208
|
+
if (latest === null || log.id > latest.id) latest = log;
|
|
209
|
+
}
|
|
210
|
+
return latest;
|
|
211
|
+
}
|
|
212
|
+
function logNeedsAttention(log) {
|
|
213
|
+
const hasHttpError = log.responseStatus !== null && log.responseStatus >= 400;
|
|
214
|
+
const hasStreamError = log.error !== null && log.error !== void 0 && log.error !== "";
|
|
215
|
+
return hasHttpError || hasStreamError;
|
|
216
|
+
}
|
|
217
|
+
function resolveInspectorPetStatus(logs, nowMs) {
|
|
218
|
+
const pendingCount = logs.filter((log) => log.responseStatus === null).length;
|
|
219
|
+
const capturedCount = logs.length;
|
|
220
|
+
if (pendingCount > 0) {
|
|
221
|
+
return {
|
|
222
|
+
mood: "active",
|
|
223
|
+
label: `${String(pendingCount)} request${pendingCount === 1 ? "" : "s"} in flight`,
|
|
224
|
+
pendingCount,
|
|
225
|
+
capturedCount
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const latest = latestCapturedLog(logs);
|
|
229
|
+
if (latest !== null && logNeedsAttention(latest)) {
|
|
230
|
+
return {
|
|
231
|
+
mood: "attention",
|
|
232
|
+
label: "Latest request needs attention",
|
|
233
|
+
pendingCount,
|
|
234
|
+
capturedCount
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (latest === null) {
|
|
238
|
+
return {
|
|
239
|
+
mood: "idle",
|
|
240
|
+
label: "Waiting for traffic",
|
|
241
|
+
pendingCount,
|
|
242
|
+
capturedCount
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const latestTimestamp = Date.parse(latest.timestamp);
|
|
246
|
+
if (Number.isFinite(latestTimestamp) && nowMs - latestTimestamp >= INSPECTOR_PET_SLEEP_AFTER_MS) {
|
|
247
|
+
return {
|
|
248
|
+
mood: "sleeping",
|
|
249
|
+
label: "All quiet",
|
|
250
|
+
pendingCount,
|
|
251
|
+
capturedCount
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
mood: "idle",
|
|
256
|
+
label: "Watching the session",
|
|
257
|
+
pendingCount,
|
|
258
|
+
capturedCount
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function createRod(start, end, radius, material) {
|
|
262
|
+
const direction = end.clone().sub(start);
|
|
263
|
+
const length = direction.length();
|
|
264
|
+
const rod = new Mesh(new CylinderGeometry(radius, radius * 0.9, length, 12), material);
|
|
265
|
+
rod.position.copy(start.clone().add(end).multiplyScalar(0.5));
|
|
266
|
+
rod.quaternion.setFromUnitVectors(new Vector3(0, 1, 0), direction.normalize());
|
|
267
|
+
return rod;
|
|
268
|
+
}
|
|
269
|
+
function addClaw(root, side, shellMaterial, accentMaterial) {
|
|
270
|
+
const clawScale = side < 0 ? 1.5 : 0.68;
|
|
271
|
+
const clawGroup = new Group();
|
|
272
|
+
const pincers = [];
|
|
273
|
+
root.add(clawGroup);
|
|
274
|
+
const shoulder = new Vector3(side * 1.2, 0.25, -0.05);
|
|
275
|
+
const wrist = new Vector3(side * (1.65 + clawScale * 0.18), 0.5, 0);
|
|
276
|
+
const arm = createRod(shoulder, wrist, 0.16 * clawScale, accentMaterial);
|
|
277
|
+
clawGroup.add(arm);
|
|
278
|
+
const palm = new Mesh(new SphereGeometry(0.55, 24, 16), shellMaterial);
|
|
279
|
+
palm.position.set(side * (1.95 + clawScale * 0.16), 0.62, 0.05);
|
|
280
|
+
palm.scale.set(1.05 * clawScale, 0.72 * clawScale, 0.55 * clawScale);
|
|
281
|
+
clawGroup.add(palm);
|
|
282
|
+
for (const pincerDirection of [-1, 1]) {
|
|
283
|
+
const pincer = new Mesh(new SphereGeometry(0.36, 20, 14), accentMaterial);
|
|
284
|
+
pincer.position.set(
|
|
285
|
+
side * (2.22 + clawScale * 0.26),
|
|
286
|
+
0.62 + pincerDirection * 0.24 * clawScale,
|
|
287
|
+
0.08
|
|
288
|
+
);
|
|
289
|
+
pincer.scale.set(1.05 * clawScale, 0.34 * clawScale, 0.42 * clawScale);
|
|
290
|
+
pincer.rotation.z = pincerDirection * side * 0.42;
|
|
291
|
+
clawGroup.add(pincer);
|
|
292
|
+
pincers.push({
|
|
293
|
+
direction: pincerDirection,
|
|
294
|
+
mesh: pincer,
|
|
295
|
+
restRotationZ: pincer.rotation.z,
|
|
296
|
+
restY: pincer.position.y
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
return { group: clawGroup, pincers, scale: clawScale };
|
|
300
|
+
}
|
|
301
|
+
function pinchPulse(cycleTime, start, duration) {
|
|
302
|
+
const progress = (cycleTime - start) / duration;
|
|
303
|
+
if (progress <= 0 || progress >= 1) return 0;
|
|
304
|
+
return Math.sin(progress * Math.PI);
|
|
305
|
+
}
|
|
306
|
+
function dominantClawGrip(elapsed) {
|
|
307
|
+
const cycleTime = elapsed % 6.8;
|
|
308
|
+
return Math.max(pinchPulse(cycleTime, 0.72, 0.82), pinchPulse(cycleTime, 1.72, 0.68));
|
|
309
|
+
}
|
|
310
|
+
function addEyes(root, shellMaterial, eyeMaterial) {
|
|
311
|
+
const eyes = [];
|
|
312
|
+
for (const side of [-1, 1]) {
|
|
313
|
+
const stalkStart = new Vector3(side * 0.48, 0.68, 0.05);
|
|
314
|
+
const stalkEnd = new Vector3(side * 0.1, 0.82, 0.07);
|
|
315
|
+
const eyeGroup = new Group();
|
|
316
|
+
eyeGroup.position.copy(stalkStart);
|
|
317
|
+
eyeGroup.add(createRod(new Vector3(0, 0, 0), stalkEnd, 0.1, shellMaterial));
|
|
318
|
+
const eye = new Mesh(new SphereGeometry(0.24, 20, 16), eyeMaterial);
|
|
319
|
+
eye.position.copy(stalkEnd);
|
|
320
|
+
eye.scale.set(1, 1, 0.85);
|
|
321
|
+
eyeGroup.add(eye);
|
|
322
|
+
const pupil = new Mesh(
|
|
323
|
+
new SphereGeometry(0.105, 16, 12),
|
|
324
|
+
new MeshPhysicalMaterial({ color: 1120295, roughness: 0.25 })
|
|
325
|
+
);
|
|
326
|
+
const pupilRest = new Vector3(stalkEnd.x, stalkEnd.y, stalkEnd.z + 0.2);
|
|
327
|
+
pupil.position.copy(pupilRest);
|
|
328
|
+
eyeGroup.add(pupil);
|
|
329
|
+
root.add(eyeGroup);
|
|
330
|
+
eyes.push({
|
|
331
|
+
group: eyeGroup,
|
|
332
|
+
phase: side < 0 ? 0 : Math.PI / 3,
|
|
333
|
+
pupil,
|
|
334
|
+
pupilRest
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return eyes;
|
|
338
|
+
}
|
|
339
|
+
function addLegs(root, legMaterial) {
|
|
340
|
+
const legs = [];
|
|
341
|
+
for (const side of [-1, 1]) {
|
|
342
|
+
for (let index = 0; index < 4; index += 1) {
|
|
343
|
+
const leg = new Group();
|
|
344
|
+
const baseY = -0.3 - index * 0.22;
|
|
345
|
+
leg.position.set(side * (0.8 + index * 0.12), baseY, -0.18);
|
|
346
|
+
leg.add(
|
|
347
|
+
createRod(
|
|
348
|
+
new Vector3(0, 0, 0),
|
|
349
|
+
new Vector3(side * (0.62 + index * 0.06), -0.34, 0),
|
|
350
|
+
0.095,
|
|
351
|
+
legMaterial
|
|
352
|
+
)
|
|
353
|
+
);
|
|
354
|
+
leg.add(
|
|
355
|
+
createRod(
|
|
356
|
+
new Vector3(side * (0.58 + index * 0.06), -0.31, 0),
|
|
357
|
+
new Vector3(side * (1.02 + index * 0.08), -0.88 + index * 0.07, 0.04),
|
|
358
|
+
0.075,
|
|
359
|
+
legMaterial
|
|
360
|
+
)
|
|
361
|
+
);
|
|
362
|
+
root.add(leg);
|
|
363
|
+
legs.push({ group: leg, phase: index * Math.PI + (side > 0 ? Math.PI / 2 : 0), side });
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return legs;
|
|
367
|
+
}
|
|
368
|
+
function createCrabScene(scene) {
|
|
369
|
+
const shellMaterial = new MeshPhysicalMaterial({
|
|
370
|
+
color: 16096779,
|
|
371
|
+
roughness: 0.34,
|
|
372
|
+
metalness: 0.04,
|
|
373
|
+
clearcoat: 0.78,
|
|
374
|
+
clearcoatRoughness: 0.18,
|
|
375
|
+
emissive: new Color(0),
|
|
376
|
+
emissiveIntensity: 0
|
|
377
|
+
});
|
|
378
|
+
const accentMaterial = new MeshPhysicalMaterial({
|
|
379
|
+
color: 16486972,
|
|
380
|
+
roughness: 0.42,
|
|
381
|
+
metalness: 0.02,
|
|
382
|
+
clearcoat: 0.52,
|
|
383
|
+
clearcoatRoughness: 0.28
|
|
384
|
+
});
|
|
385
|
+
const legMaterial = new MeshPhysicalMaterial({
|
|
386
|
+
color: 14251782,
|
|
387
|
+
roughness: 0.48,
|
|
388
|
+
clearcoat: 0.35,
|
|
389
|
+
clearcoatRoughness: 0.35
|
|
390
|
+
});
|
|
391
|
+
const eyeMaterial = new MeshPhysicalMaterial({
|
|
392
|
+
color: 16776171,
|
|
393
|
+
roughness: 0.22,
|
|
394
|
+
clearcoat: 0.8,
|
|
395
|
+
clearcoatRoughness: 0.12
|
|
396
|
+
});
|
|
397
|
+
const root = new Group();
|
|
398
|
+
root.rotation.x = -0.12;
|
|
399
|
+
root.rotation.y = -0.08;
|
|
400
|
+
root.scale.setScalar(1.08);
|
|
401
|
+
scene.add(root);
|
|
402
|
+
const shadow = new Mesh(
|
|
403
|
+
new CircleGeometry(1.65, 40),
|
|
404
|
+
new MeshBasicMaterial({ color: 1120295, transparent: true, opacity: 0.16, depthWrite: false })
|
|
405
|
+
);
|
|
406
|
+
shadow.position.set(0, -1.33, -0.65);
|
|
407
|
+
shadow.scale.set(1.4, 0.34, 1);
|
|
408
|
+
root.add(shadow);
|
|
409
|
+
const body = new Mesh(new SphereGeometry(1, 36, 24), shellMaterial);
|
|
410
|
+
body.position.set(0, 0.02, 0);
|
|
411
|
+
body.scale.set(1.58, 0.92, 0.68);
|
|
412
|
+
root.add(body);
|
|
413
|
+
const lowerShell = new Mesh(new SphereGeometry(0.92, 28, 20), accentMaterial);
|
|
414
|
+
lowerShell.position.set(0, -0.48, 0.22);
|
|
415
|
+
lowerShell.scale.set(1.28, 0.42, 0.56);
|
|
416
|
+
root.add(lowerShell);
|
|
417
|
+
const dominantClaw = addClaw(root, -1, shellMaterial, accentMaterial);
|
|
418
|
+
addClaw(root, 1, shellMaterial, accentMaterial);
|
|
419
|
+
const eyes = addEyes(root, shellMaterial, eyeMaterial);
|
|
420
|
+
const legs = addLegs(root, legMaterial);
|
|
421
|
+
scene.add(new AmbientLight(16775149, 1.65));
|
|
422
|
+
scene.add(new HemisphereLight(16775149, 1515571, 2.15));
|
|
423
|
+
const keyLight = new DirectionalLight(16777215, 3.6);
|
|
424
|
+
keyLight.position.set(3.5, 4.5, 6);
|
|
425
|
+
scene.add(keyLight);
|
|
426
|
+
const fillLight = new DirectionalLight(16498468, 1.35);
|
|
427
|
+
fillLight.position.set(-4, 1.5, 4);
|
|
428
|
+
scene.add(fillLight);
|
|
429
|
+
const rimLight = new PointLight(16096779, 1.8, 12, 2);
|
|
430
|
+
rimLight.position.set(0, 1.8, 4.5);
|
|
431
|
+
scene.add(rimLight);
|
|
432
|
+
return { bodyMaterial: shellMaterial, dominantClaw, eyes, legs, rimLight, root };
|
|
433
|
+
}
|
|
434
|
+
function moodColor(mood) {
|
|
435
|
+
switch (mood) {
|
|
436
|
+
case "active":
|
|
437
|
+
return 2282478;
|
|
438
|
+
case "attention":
|
|
439
|
+
return 15680580;
|
|
440
|
+
case "idle":
|
|
441
|
+
return 16096779;
|
|
442
|
+
case "sleeping":
|
|
443
|
+
return 9741240;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function isDisposableMesh(object) {
|
|
447
|
+
return object instanceof Mesh;
|
|
448
|
+
}
|
|
449
|
+
function disposeScene(scene) {
|
|
450
|
+
const materials = /* @__PURE__ */ new Set();
|
|
451
|
+
scene.traverse((object) => {
|
|
452
|
+
if (!isDisposableMesh(object)) return;
|
|
453
|
+
object.geometry.dispose();
|
|
454
|
+
const material = object.material;
|
|
455
|
+
if (Array.isArray(material)) {
|
|
456
|
+
for (const item of material) materials.add(item);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
materials.add(material);
|
|
460
|
+
});
|
|
461
|
+
for (const material of materials) material.dispose();
|
|
462
|
+
}
|
|
463
|
+
function InspectorPetCrab3D({
|
|
464
|
+
mood,
|
|
465
|
+
moving,
|
|
466
|
+
reduceMotion
|
|
467
|
+
}) {
|
|
468
|
+
const canvasRef = reactExports.useRef(null);
|
|
469
|
+
const moodRef = reactExports.useRef(mood);
|
|
470
|
+
const movingRef = reactExports.useRef(moving);
|
|
471
|
+
const reduceMotionRef = reactExports.useRef(reduceMotion);
|
|
472
|
+
const [renderFailed, setRenderFailed] = reactExports.useState(false);
|
|
473
|
+
reactExports.useEffect(() => {
|
|
474
|
+
moodRef.current = mood;
|
|
475
|
+
}, [mood]);
|
|
476
|
+
reactExports.useEffect(() => {
|
|
477
|
+
movingRef.current = moving;
|
|
478
|
+
}, [moving]);
|
|
479
|
+
reactExports.useEffect(() => {
|
|
480
|
+
reduceMotionRef.current = reduceMotion;
|
|
481
|
+
}, [reduceMotion]);
|
|
482
|
+
reactExports.useEffect(() => {
|
|
483
|
+
const canvas = canvasRef.current;
|
|
484
|
+
if (canvas === null) return void 0;
|
|
485
|
+
let renderer;
|
|
486
|
+
try {
|
|
487
|
+
renderer = new WebGLRenderer({
|
|
488
|
+
alpha: true,
|
|
489
|
+
antialias: true,
|
|
490
|
+
canvas,
|
|
491
|
+
powerPreference: "low-power",
|
|
492
|
+
preserveDrawingBuffer: true
|
|
493
|
+
});
|
|
494
|
+
} catch {
|
|
495
|
+
setRenderFailed(true);
|
|
496
|
+
return void 0;
|
|
497
|
+
}
|
|
498
|
+
renderer.setClearColor(0, 0);
|
|
499
|
+
renderer.outputColorSpace = SRGBColorSpace;
|
|
500
|
+
renderer.toneMapping = ACESFilmicToneMapping;
|
|
501
|
+
renderer.toneMappingExposure = 1.18;
|
|
502
|
+
const scene = new Scene();
|
|
503
|
+
const camera = new OrthographicCamera(-3.65, 3.65, 3.65, -3.65, 0.1, 20);
|
|
504
|
+
camera.position.set(0, 0.05, 8);
|
|
505
|
+
camera.lookAt(0, 0, 0);
|
|
506
|
+
const parts = createCrabScene(scene);
|
|
507
|
+
const startedAt = window.performance.now();
|
|
508
|
+
let lastFrameAt = 0;
|
|
509
|
+
const renderFrame = (timestamp) => {
|
|
510
|
+
if (timestamp - lastFrameAt < 32) return;
|
|
511
|
+
lastFrameAt = timestamp;
|
|
512
|
+
const elapsed = (timestamp - startedAt) / 1e3;
|
|
513
|
+
const motionAllowed = !reduceMotionRef.current;
|
|
514
|
+
const gait = movingRef.current ? 1 : moodRef.current === "active" ? 0.42 : 0;
|
|
515
|
+
const idleMotion = motionAllowed ? Math.sin(elapsed * 0.85) : 0;
|
|
516
|
+
const stepMotion = motionAllowed ? Math.sin(elapsed * 3.4) : 0;
|
|
517
|
+
const clawGrip = motionAllowed ? dominantClawGrip(elapsed) : 0;
|
|
518
|
+
parts.root.position.y = idleMotion * 0.035 + Math.abs(stepMotion) * 0.055 * gait;
|
|
519
|
+
parts.root.rotation.y = -0.08 + idleMotion * 0.055;
|
|
520
|
+
parts.root.rotation.z = stepMotion * 0.028 * gait;
|
|
521
|
+
parts.dominantClaw.group.rotation.z = -clawGrip * 0.035;
|
|
522
|
+
for (const pincer of parts.dominantClaw.pincers) {
|
|
523
|
+
pincer.mesh.position.y = pincer.restY - pincer.direction * parts.dominantClaw.scale * 0.16 * clawGrip;
|
|
524
|
+
pincer.mesh.rotation.z = pincer.restRotationZ * (1 - clawGrip * 0.72);
|
|
525
|
+
}
|
|
526
|
+
for (const leg of parts.legs) {
|
|
527
|
+
leg.group.rotation.z = motionAllowed && gait > 0 ? Math.sin(elapsed * 4.25 + leg.phase) * 0.2 * leg.side * gait : 0;
|
|
528
|
+
leg.group.rotation.x = motionAllowed && gait > 0 ? stepMotion * 0.045 * gait : 0;
|
|
529
|
+
}
|
|
530
|
+
for (const eye of parts.eyes) {
|
|
531
|
+
const gaze = motionAllowed ? Math.sin(elapsed * 0.72 + eye.phase) : 0;
|
|
532
|
+
const lift = motionAllowed ? Math.cos(elapsed * 0.9 + eye.phase) : 0;
|
|
533
|
+
eye.group.rotation.z = gaze * 0.075;
|
|
534
|
+
eye.group.rotation.x = lift * 0.025;
|
|
535
|
+
eye.pupil.position.set(
|
|
536
|
+
eye.pupilRest.x + gaze * 0.055,
|
|
537
|
+
eye.pupilRest.y + lift * 0.025,
|
|
538
|
+
eye.pupilRest.z
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
const color = moodColor(moodRef.current);
|
|
542
|
+
parts.rimLight.color.setHex(color);
|
|
543
|
+
parts.rimLight.intensity = moodRef.current === "attention" ? 3.2 : 1.8;
|
|
544
|
+
parts.bodyMaterial.emissive.setHex(color);
|
|
545
|
+
parts.bodyMaterial.emissiveIntensity = moodRef.current === "active" ? 0.12 : 0.035;
|
|
546
|
+
renderer.render(scene, camera);
|
|
547
|
+
};
|
|
548
|
+
const resize = () => {
|
|
549
|
+
const width = Math.max(canvas.clientWidth, 1);
|
|
550
|
+
const height = Math.max(canvas.clientHeight, 1);
|
|
551
|
+
renderer.setDrawingBufferSize(width, height, Math.min(window.devicePixelRatio, 2));
|
|
552
|
+
renderer.render(scene, camera);
|
|
553
|
+
};
|
|
554
|
+
const resizeObserver = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(resize);
|
|
555
|
+
if (resizeObserver === null) {
|
|
556
|
+
window.addEventListener("resize", resize);
|
|
557
|
+
} else {
|
|
558
|
+
resizeObserver.observe(canvas);
|
|
559
|
+
}
|
|
560
|
+
resize();
|
|
561
|
+
const handleContextLost = (event) => {
|
|
562
|
+
event.preventDefault();
|
|
563
|
+
setRenderFailed(true);
|
|
564
|
+
};
|
|
565
|
+
canvas.addEventListener("webglcontextlost", handleContextLost);
|
|
566
|
+
renderer.setAnimationLoop(renderFrame);
|
|
567
|
+
return () => {
|
|
568
|
+
renderer.setAnimationLoop(null);
|
|
569
|
+
if (resizeObserver === null) {
|
|
570
|
+
window.removeEventListener("resize", resize);
|
|
571
|
+
} else {
|
|
572
|
+
resizeObserver.disconnect();
|
|
573
|
+
}
|
|
574
|
+
canvas.removeEventListener("webglcontextlost", handleContextLost);
|
|
575
|
+
disposeScene(scene);
|
|
576
|
+
renderer.dispose();
|
|
577
|
+
};
|
|
578
|
+
}, []);
|
|
579
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "relative flex size-24 items-center justify-center", "aria-hidden": "true", children: [
|
|
580
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
581
|
+
"canvas",
|
|
582
|
+
{
|
|
583
|
+
ref: canvasRef,
|
|
584
|
+
className: renderFailed ? "hidden" : "block size-full bg-transparent",
|
|
585
|
+
"data-inspector-pet-canvas": "true"
|
|
586
|
+
}
|
|
587
|
+
),
|
|
588
|
+
renderFailed && /* @__PURE__ */ jsxRuntimeExports.jsx(CrabLogo, { className: "size-22 text-amber-500 drop-shadow-[0_0_18px_rgba(245,158,11,0.28)]" })
|
|
589
|
+
] });
|
|
590
|
+
}
|
|
591
|
+
const INSPECTOR_PET_ROAMING_STORAGE_KEY = "agent-inspector.pet.roaming";
|
|
592
|
+
const INSPECTOR_PET_MIN_PAUSE_MS = 11e3;
|
|
593
|
+
const INSPECTOR_PET_PAUSE_WINDOW_MS = 9e3;
|
|
594
|
+
const INSPECTOR_PET_SCUTTLE_MS = 7200;
|
|
595
|
+
const INSPECTOR_PET_PANEL_DISMISS_MS = 6e3;
|
|
596
|
+
const INSPECTOR_PET_REACTION_MS = 760;
|
|
597
|
+
const INSPECTOR_PET_DRAG_THRESHOLD = 4;
|
|
598
|
+
const INSPECTOR_PET_TOP_LAYER_Z_INDEX = 2147483647;
|
|
599
|
+
function readViewport() {
|
|
600
|
+
if (typeof window === "undefined") return { width: 1280, height: 720, scale: 1 };
|
|
601
|
+
const rawScale = window.getComputedStyle(document.documentElement).getPropertyValue("--inspector-ui-scale");
|
|
602
|
+
const parsedScale = Number.parseFloat(rawScale);
|
|
603
|
+
const scale = Number.isFinite(parsedScale) && parsedScale > 0 ? parsedScale : 1;
|
|
604
|
+
return {
|
|
605
|
+
width: Math.max(window.innerWidth, INSPECTOR_PET_MARGIN * 2),
|
|
606
|
+
height: Math.max(window.innerHeight, INSPECTOR_PET_MARGIN * 2),
|
|
607
|
+
scale
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function readStoredRoaming() {
|
|
611
|
+
if (typeof window === "undefined") return true;
|
|
612
|
+
try {
|
|
613
|
+
return window.localStorage.getItem(INSPECTOR_PET_ROAMING_STORAGE_KEY) !== "0";
|
|
614
|
+
} catch {
|
|
615
|
+
return true;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
function moodDotClass(mood) {
|
|
619
|
+
switch (mood) {
|
|
620
|
+
case "active":
|
|
621
|
+
return "bg-cyan-400 shadow-[0_0_9px_rgba(34,211,238,0.65)]";
|
|
622
|
+
case "attention":
|
|
623
|
+
return "bg-red-500 shadow-[0_0_9px_rgba(239,68,68,0.55)]";
|
|
624
|
+
case "idle":
|
|
625
|
+
return "bg-amber-400 shadow-[0_0_8px_rgba(251,191,36,0.45)]";
|
|
626
|
+
case "sleeping":
|
|
627
|
+
return "bg-muted-foreground/45";
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function moodMotionClass(mood) {
|
|
631
|
+
switch (mood) {
|
|
632
|
+
case "active":
|
|
633
|
+
return "inspector-pet-active";
|
|
634
|
+
case "attention":
|
|
635
|
+
return "inspector-pet-attention";
|
|
636
|
+
case "idle":
|
|
637
|
+
return "";
|
|
638
|
+
case "sleeping":
|
|
639
|
+
return "inspector-pet-sleeping";
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function InspectorPet({ logs }) {
|
|
643
|
+
const [portalHost, setPortalHost] = reactExports.useState(null);
|
|
644
|
+
const [viewport, setViewport] = reactExports.useState(readViewport);
|
|
645
|
+
const [position, setPosition] = reactExports.useState({
|
|
646
|
+
x: INSPECTOR_PET_MARGIN,
|
|
647
|
+
y: INSPECTOR_PET_MARGIN
|
|
648
|
+
});
|
|
649
|
+
const [clockMs, setClockMs] = reactExports.useState(() => Date.now());
|
|
650
|
+
const [scuttling, setScuttling] = reactExports.useState(false);
|
|
651
|
+
const [panelTick, setPanelTick] = reactExports.useState(0);
|
|
652
|
+
const [panelVisible, setPanelVisible] = reactExports.useState(false);
|
|
653
|
+
const [reactionTick, setReactionTick] = reactExports.useState(0);
|
|
654
|
+
const [reactionVisible, setReactionVisible] = reactExports.useState(false);
|
|
655
|
+
const [dragging, setDragging] = reactExports.useState(false);
|
|
656
|
+
const [roaming, setRoaming] = reactExports.useState(readStoredRoaming);
|
|
657
|
+
const [reduceMotion, setReduceMotion] = reactExports.useState(false);
|
|
658
|
+
const dragStateRef = reactExports.useRef(null);
|
|
659
|
+
const dragOccurredRef = reactExports.useRef(false);
|
|
660
|
+
const status = reactExports.useMemo(() => resolveInspectorPetStatus(logs, clockMs), [clockMs, logs]);
|
|
661
|
+
const panelPosition = reactExports.useMemo(
|
|
662
|
+
() => inspectorPetPanelPosition(position, viewport),
|
|
663
|
+
[position, viewport]
|
|
664
|
+
);
|
|
665
|
+
reactExports.useEffect(() => setPortalHost(document.body), []);
|
|
666
|
+
reactExports.useEffect(() => {
|
|
667
|
+
const nextViewport = readViewport();
|
|
668
|
+
setViewport(nextViewport);
|
|
669
|
+
setPosition(randomInspectorPetEdgePosition(nextViewport, Math.random()));
|
|
670
|
+
}, []);
|
|
671
|
+
reactExports.useEffect(() => {
|
|
672
|
+
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
673
|
+
const handleChange = (event) => setReduceMotion(event.matches);
|
|
674
|
+
setReduceMotion(mediaQuery.matches);
|
|
675
|
+
mediaQuery.addEventListener("change", handleChange);
|
|
676
|
+
return () => mediaQuery.removeEventListener("change", handleChange);
|
|
677
|
+
}, []);
|
|
678
|
+
reactExports.useEffect(() => {
|
|
679
|
+
const intervalId = window.setInterval(() => setClockMs(Date.now()), 15e3);
|
|
680
|
+
return () => window.clearInterval(intervalId);
|
|
681
|
+
}, []);
|
|
682
|
+
reactExports.useEffect(() => {
|
|
683
|
+
try {
|
|
684
|
+
window.localStorage.setItem(INSPECTOR_PET_ROAMING_STORAGE_KEY, roaming ? "1" : "0");
|
|
685
|
+
} catch {
|
|
686
|
+
}
|
|
687
|
+
}, [roaming]);
|
|
688
|
+
reactExports.useEffect(() => {
|
|
689
|
+
if (!roaming || dragging || reduceMotion) return void 0;
|
|
690
|
+
let pauseTimeoutId = null;
|
|
691
|
+
let scuttleTimeoutId = null;
|
|
692
|
+
const scheduleScuttle = () => {
|
|
693
|
+
const delay = INSPECTOR_PET_MIN_PAUSE_MS + Math.random() * INSPECTOR_PET_PAUSE_WINDOW_MS;
|
|
694
|
+
pauseTimeoutId = window.setTimeout(() => {
|
|
695
|
+
setScuttling(true);
|
|
696
|
+
setPosition(
|
|
697
|
+
(current) => nextInspectorPetWalkingPosition(current, viewport, Math.random(), Math.random())
|
|
698
|
+
);
|
|
699
|
+
scuttleTimeoutId = window.setTimeout(() => {
|
|
700
|
+
setScuttling(false);
|
|
701
|
+
scheduleScuttle();
|
|
702
|
+
}, INSPECTOR_PET_SCUTTLE_MS);
|
|
703
|
+
}, delay);
|
|
704
|
+
};
|
|
705
|
+
scheduleScuttle();
|
|
706
|
+
return () => {
|
|
707
|
+
if (pauseTimeoutId !== null) window.clearTimeout(pauseTimeoutId);
|
|
708
|
+
if (scuttleTimeoutId !== null) window.clearTimeout(scuttleTimeoutId);
|
|
709
|
+
};
|
|
710
|
+
}, [dragging, reduceMotion, roaming, viewport]);
|
|
711
|
+
reactExports.useEffect(() => {
|
|
712
|
+
const handleResize = () => {
|
|
713
|
+
const nextViewport = readViewport();
|
|
714
|
+
setScuttling(false);
|
|
715
|
+
setViewport(nextViewport);
|
|
716
|
+
setPosition((current) => snapInspectorPetToEdge(current, nextViewport));
|
|
717
|
+
};
|
|
718
|
+
window.addEventListener("resize", handleResize);
|
|
719
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
720
|
+
}, []);
|
|
721
|
+
reactExports.useEffect(() => {
|
|
722
|
+
if (!panelVisible) return void 0;
|
|
723
|
+
const timeoutId = window.setTimeout(
|
|
724
|
+
() => setPanelVisible(false),
|
|
725
|
+
INSPECTOR_PET_PANEL_DISMISS_MS
|
|
726
|
+
);
|
|
727
|
+
return () => window.clearTimeout(timeoutId);
|
|
728
|
+
}, [panelTick, panelVisible]);
|
|
729
|
+
reactExports.useEffect(() => {
|
|
730
|
+
if (!reactionVisible) return void 0;
|
|
731
|
+
const timeoutId = window.setTimeout(() => setReactionVisible(false), INSPECTOR_PET_REACTION_MS);
|
|
732
|
+
return () => window.clearTimeout(timeoutId);
|
|
733
|
+
}, [reactionTick, reactionVisible]);
|
|
734
|
+
const handlePet = reactExports.useCallback(() => {
|
|
735
|
+
if (dragOccurredRef.current) {
|
|
736
|
+
dragOccurredRef.current = false;
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
setClockMs(Date.now());
|
|
740
|
+
setPanelTick((current) => current + 1);
|
|
741
|
+
setPanelVisible(true);
|
|
742
|
+
setReactionTick((current) => current + 1);
|
|
743
|
+
setReactionVisible(true);
|
|
744
|
+
}, []);
|
|
745
|
+
const handlePointerDown = reactExports.useCallback((event) => {
|
|
746
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
747
|
+
dragOccurredRef.current = false;
|
|
748
|
+
dragStateRef.current = {
|
|
749
|
+
pointerId: event.pointerId,
|
|
750
|
+
offsetX: event.clientX - rect.left,
|
|
751
|
+
offsetY: event.clientY - rect.top,
|
|
752
|
+
startX: event.clientX,
|
|
753
|
+
startY: event.clientY,
|
|
754
|
+
moved: false
|
|
755
|
+
};
|
|
756
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
757
|
+
setScuttling(false);
|
|
758
|
+
setPanelVisible(false);
|
|
759
|
+
setDragging(true);
|
|
760
|
+
}, []);
|
|
761
|
+
const handlePointerMove = reactExports.useCallback(
|
|
762
|
+
(event) => {
|
|
763
|
+
const dragState = dragStateRef.current;
|
|
764
|
+
if (dragState === null || dragState.pointerId !== event.pointerId) return;
|
|
765
|
+
const moved = dragState.moved || Math.abs(event.clientX - dragState.startX) >= INSPECTOR_PET_DRAG_THRESHOLD || Math.abs(event.clientY - dragState.startY) >= INSPECTOR_PET_DRAG_THRESHOLD;
|
|
766
|
+
dragState.moved = moved;
|
|
767
|
+
dragOccurredRef.current = moved;
|
|
768
|
+
setPosition(
|
|
769
|
+
clampInspectorPetPosition(
|
|
770
|
+
{
|
|
771
|
+
x: event.clientX - dragState.offsetX,
|
|
772
|
+
y: event.clientY - dragState.offsetY
|
|
773
|
+
},
|
|
774
|
+
viewport
|
|
775
|
+
)
|
|
776
|
+
);
|
|
777
|
+
},
|
|
778
|
+
[viewport]
|
|
779
|
+
);
|
|
780
|
+
const handlePointerUp = reactExports.useCallback(
|
|
781
|
+
(event) => {
|
|
782
|
+
const dragState = dragStateRef.current;
|
|
783
|
+
if (dragState === null || dragState.pointerId !== event.pointerId) return;
|
|
784
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
785
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
786
|
+
}
|
|
787
|
+
dragOccurredRef.current = dragState.moved;
|
|
788
|
+
dragStateRef.current = null;
|
|
789
|
+
setDragging(false);
|
|
790
|
+
setPosition((current) => snapInspectorPetToEdge(current, viewport));
|
|
791
|
+
},
|
|
792
|
+
[viewport]
|
|
793
|
+
);
|
|
794
|
+
const handlePointerCancel = reactExports.useCallback((event) => {
|
|
795
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
796
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
797
|
+
}
|
|
798
|
+
dragStateRef.current = null;
|
|
799
|
+
dragOccurredRef.current = false;
|
|
800
|
+
setDragging(false);
|
|
801
|
+
}, []);
|
|
802
|
+
const handleToggleRoaming = reactExports.useCallback(() => {
|
|
803
|
+
setScuttling(false);
|
|
804
|
+
setRoaming((current) => !current);
|
|
805
|
+
}, []);
|
|
806
|
+
const petStyle = reactExports.useMemo(
|
|
807
|
+
() => ({
|
|
808
|
+
transform: `translate3d(${String(position.x)}px, ${String(position.y)}px, 0) scale(${dragging ? "1.04" : "1"})`,
|
|
809
|
+
transition: dragging ? "none" : scuttling ? `transform ${String(INSPECTOR_PET_SCUTTLE_MS)}ms cubic-bezier(0.22, 0.72, 0.32, 1)` : "transform 900ms cubic-bezier(0.22, 0.72, 0.32, 1)",
|
|
810
|
+
touchAction: "none"
|
|
811
|
+
}),
|
|
812
|
+
[dragging, position.x, position.y, scuttling]
|
|
813
|
+
);
|
|
814
|
+
const panelStyle = reactExports.useMemo(
|
|
815
|
+
() => ({ left: panelPosition.x, top: panelPosition.y }),
|
|
816
|
+
[panelPosition.x, panelPosition.y]
|
|
817
|
+
);
|
|
818
|
+
const roamingLabel = roaming ? "Pause pet roaming" : "Resume pet roaming";
|
|
819
|
+
if (portalHost === null) return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
|
|
820
|
+
return reactDomExports.createPortal(
|
|
821
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
822
|
+
"div",
|
|
823
|
+
{
|
|
824
|
+
className: "pointer-events-none fixed inset-0 isolate",
|
|
825
|
+
style: { zIndex: INSPECTOR_PET_TOP_LAYER_Z_INDEX },
|
|
826
|
+
"data-inspector-pet-layer": "true",
|
|
827
|
+
children: [
|
|
828
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
829
|
+
"button",
|
|
830
|
+
{
|
|
831
|
+
type: "button",
|
|
832
|
+
className: cn(
|
|
833
|
+
"pointer-events-auto fixed left-0 top-0 z-10 flex size-28 items-center justify-center bg-transparent text-foreground outline-none transition-[filter,opacity] duration-200 hover:opacity-95 hover:drop-shadow-[0_0_28px_rgba(245,158,11,0.32)] focus-visible:drop-shadow-[0_0_14px_rgba(251,191,36,0.72)]",
|
|
834
|
+
dragging ? "cursor-grabbing" : "cursor-grab"
|
|
835
|
+
),
|
|
836
|
+
style: petStyle,
|
|
837
|
+
"data-pet-mood": status.mood,
|
|
838
|
+
"data-pet-moving": scuttling ? "true" : "false",
|
|
839
|
+
onClick: handlePet,
|
|
840
|
+
onPointerDown: handlePointerDown,
|
|
841
|
+
onPointerMove: handlePointerMove,
|
|
842
|
+
onPointerUp: handlePointerUp,
|
|
843
|
+
onPointerCancel: handlePointerCancel,
|
|
844
|
+
"aria-label": `Inspector pet: ${status.label}`,
|
|
845
|
+
title: status.label,
|
|
846
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
847
|
+
"span",
|
|
848
|
+
{
|
|
849
|
+
className: cn(
|
|
850
|
+
"relative z-10 flex size-24 items-center justify-center",
|
|
851
|
+
reactionVisible && "inspector-pet-patted"
|
|
852
|
+
),
|
|
853
|
+
"aria-hidden": "true",
|
|
854
|
+
children: [
|
|
855
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
856
|
+
"span",
|
|
857
|
+
{
|
|
858
|
+
className: cn(
|
|
859
|
+
"relative flex size-24 items-center justify-center",
|
|
860
|
+
moodMotionClass(status.mood)
|
|
861
|
+
),
|
|
862
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "relative flex size-24 items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
863
|
+
InspectorPetCrab3D,
|
|
864
|
+
{
|
|
865
|
+
mood: status.mood,
|
|
866
|
+
moving: scuttling && !dragging,
|
|
867
|
+
reduceMotion
|
|
868
|
+
}
|
|
869
|
+
) })
|
|
870
|
+
}
|
|
871
|
+
),
|
|
872
|
+
reactionVisible && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
873
|
+
Heart,
|
|
874
|
+
{
|
|
875
|
+
className: "inspector-pet-heart absolute -right-2 -top-3 size-5 fill-amber-400 text-amber-400"
|
|
876
|
+
},
|
|
877
|
+
reactionTick
|
|
878
|
+
)
|
|
879
|
+
]
|
|
880
|
+
}
|
|
881
|
+
)
|
|
882
|
+
}
|
|
883
|
+
),
|
|
884
|
+
panelVisible && /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
885
|
+
"div",
|
|
886
|
+
{
|
|
887
|
+
className: "pointer-events-auto fixed z-20 w-48 rounded-md border border-border/80 bg-popover/95 px-3 py-2 text-popover-foreground shadow-[0_14px_34px_rgba(0,0,0,0.28)] backdrop-blur",
|
|
888
|
+
style: panelStyle,
|
|
889
|
+
role: "status",
|
|
890
|
+
"aria-live": "polite",
|
|
891
|
+
children: [
|
|
892
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
893
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: cn("size-2 shrink-0 rounded-full", moodDotClass(status.mood)) }),
|
|
894
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "min-w-0 flex-1 truncate text-xs font-medium", children: status.label }),
|
|
895
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
896
|
+
"button",
|
|
897
|
+
{
|
|
898
|
+
type: "button",
|
|
899
|
+
className: "inline-flex size-6 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none",
|
|
900
|
+
onClick: handleToggleRoaming,
|
|
901
|
+
"aria-label": roamingLabel,
|
|
902
|
+
title: roamingLabel,
|
|
903
|
+
children: roaming ? /* @__PURE__ */ jsxRuntimeExports.jsx(Pause, { className: "size-3.5" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Play, { className: "size-3.5" })
|
|
904
|
+
}
|
|
905
|
+
)
|
|
906
|
+
] }),
|
|
907
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-1 flex items-center justify-between gap-3 font-mono text-[10px] text-muted-foreground", children: [
|
|
908
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
|
|
909
|
+
String(status.capturedCount),
|
|
910
|
+
" captured"
|
|
911
|
+
] }),
|
|
912
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: status.pendingCount > 0 ? `${String(status.pendingCount)} active` : scuttling ? "Scuttling" : roaming ? "Resting" : "Paused" })
|
|
913
|
+
] })
|
|
914
|
+
]
|
|
915
|
+
}
|
|
916
|
+
)
|
|
917
|
+
]
|
|
918
|
+
}
|
|
919
|
+
),
|
|
920
|
+
portalHost
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
export {
|
|
924
|
+
InspectorPet
|
|
925
|
+
};
|