@tinyweb_dev/agent-framework-chat-ui 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/components/Composer.d.ts +38 -0
  2. package/dist/components/Composer.d.ts.map +1 -0
  3. package/dist/components/Header.d.ts +7 -0
  4. package/dist/components/Header.d.ts.map +1 -0
  5. package/dist/components/Hero.d.ts +6 -0
  6. package/dist/components/Hero.d.ts.map +1 -0
  7. package/dist/components/RealtimeCallOverlay.d.ts +68 -0
  8. package/dist/components/RealtimeCallOverlay.d.ts.map +1 -0
  9. package/dist/components/RealtimeOrb.d.ts +21 -0
  10. package/dist/components/RealtimeOrb.d.ts.map +1 -0
  11. package/{src/components/Sidebar.tsx → dist/components/Sidebar.d.ts} +5 -9
  12. package/dist/components/Sidebar.d.ts.map +1 -0
  13. package/dist/components/TinywebChat.d.ts +3 -0
  14. package/dist/components/TinywebChat.d.ts.map +1 -0
  15. package/dist/components/Transcript.d.ts +20 -0
  16. package/dist/components/Transcript.d.ts.map +1 -0
  17. package/dist/components/WireOrbEffect.d.ts +17 -0
  18. package/dist/components/WireOrbEffect.d.ts.map +1 -0
  19. package/dist/components/condense/CondensePill.d.ts +11 -0
  20. package/dist/components/condense/CondensePill.d.ts.map +1 -0
  21. package/dist/components/messages/AssistantMessage.d.ts +10 -0
  22. package/dist/components/messages/AssistantMessage.d.ts.map +1 -0
  23. package/dist/components/messages/ErrorMessage.d.ts +7 -0
  24. package/dist/components/messages/ErrorMessage.d.ts.map +1 -0
  25. package/dist/components/messages/ToolMessage.d.ts +17 -0
  26. package/dist/components/messages/ToolMessage.d.ts.map +1 -0
  27. package/dist/components/messages/UserMessage.d.ts +7 -0
  28. package/dist/components/messages/UserMessage.d.ts.map +1 -0
  29. package/dist/components/tool/ExecRenderer.d.ts +14 -0
  30. package/dist/components/tool/ExecRenderer.d.ts.map +1 -0
  31. package/dist/components/tool/ImageRenderer.d.ts +16 -0
  32. package/dist/components/tool/ImageRenderer.d.ts.map +1 -0
  33. package/dist/components/tool/JsonRenderer.d.ts +11 -0
  34. package/dist/components/tool/JsonRenderer.d.ts.map +1 -0
  35. package/dist/components/tool/ToolCard.d.ts +29 -0
  36. package/dist/components/tool/ToolCard.d.ts.map +1 -0
  37. package/dist/components/tool/builtinRenderers.d.ts +9 -0
  38. package/dist/components/tool/builtinRenderers.d.ts.map +1 -0
  39. package/dist/hooks/useAgentChat.d.ts +46 -0
  40. package/dist/hooks/useAgentChat.d.ts.map +1 -0
  41. package/dist/hooks/useAnchorLatestUser.d.ts +15 -0
  42. package/dist/hooks/useAnchorLatestUser.d.ts.map +1 -0
  43. package/dist/hooks/useInitialScrollToEnd.d.ts +15 -0
  44. package/dist/hooks/useInitialScrollToEnd.d.ts.map +1 -0
  45. package/dist/hooks/useNdjsonStream.d.ts +11 -0
  46. package/dist/hooks/useNdjsonStream.d.ts.map +1 -0
  47. package/dist/hooks/useRealtimeCall.d.ts +112 -0
  48. package/dist/hooks/useRealtimeCall.d.ts.map +1 -0
  49. package/dist/index.cjs +3160 -0
  50. package/dist/index.cjs.map +1 -0
  51. package/dist/index.d.ts +20 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +3126 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/markdown/render.d.ts +2 -0
  56. package/dist/markdown/render.d.ts.map +1 -0
  57. package/dist/types.d.ts +257 -0
  58. package/dist/types.d.ts.map +1 -0
  59. package/dist/util/attachments.d.ts +28 -0
  60. package/dist/util/attachments.d.ts.map +1 -0
  61. package/dist/util/escape.d.ts +2 -0
  62. package/dist/util/escape.d.ts.map +1 -0
  63. package/dist/util/theme.d.ts +13 -0
  64. package/dist/util/theme.d.ts.map +1 -0
  65. package/dist/util/tool-detect.d.ts +26 -0
  66. package/dist/util/tool-detect.d.ts.map +1 -0
  67. package/dist/util/tool-labels.d.ts +11 -0
  68. package/dist/util/tool-labels.d.ts.map +1 -0
  69. package/package.json +14 -14
  70. package/src/components/Composer.tsx +0 -267
  71. package/src/components/Header.tsx +0 -16
  72. package/src/components/Hero.tsx +0 -16
  73. package/src/components/RealtimeCallOverlay.tsx +0 -894
  74. package/src/components/RealtimeOrb.tsx +0 -388
  75. package/src/components/TinywebChat.tsx +0 -95
  76. package/src/components/Transcript.tsx +0 -146
  77. package/src/components/WireOrbEffect.tsx +0 -556
  78. package/src/components/condense/CondensePill.tsx +0 -77
  79. package/src/components/messages/AssistantMessage.tsx +0 -15
  80. package/src/components/messages/ErrorMessage.tsx +0 -12
  81. package/src/components/messages/ToolMessage.tsx +0 -49
  82. package/src/components/messages/UserMessage.tsx +0 -37
  83. package/src/components/tool/ExecRenderer.tsx +0 -71
  84. package/src/components/tool/ImageRenderer.tsx +0 -47
  85. package/src/components/tool/JsonRenderer.tsx +0 -24
  86. package/src/components/tool/ToolCard.tsx +0 -65
  87. package/src/components/tool/builtinRenderers.tsx +0 -456
  88. package/src/hooks/useAgentChat.ts +0 -454
  89. package/src/hooks/useAnchorLatestUser.ts +0 -99
  90. package/src/hooks/useInitialScrollToEnd.ts +0 -41
  91. package/src/hooks/useNdjsonStream.ts +0 -71
  92. package/src/hooks/useRealtimeCall.ts +0 -452
  93. package/src/index.ts +0 -45
  94. package/src/markdown/render.ts +0 -121
  95. package/src/types.ts +0 -241
  96. package/src/util/attachments.ts +0 -87
  97. package/src/util/escape.ts +0 -16
  98. package/src/util/theme.ts +0 -40
  99. package/src/util/tool-detect.ts +0 -65
  100. package/src/util/tool-labels.ts +0 -34
  101. /package/{src → dist}/styles.css +0 -0
@@ -1,556 +0,0 @@
1
- "use client"
2
-
3
- /**
4
- * Wireframe Orb + Dust — Three.js voice-call visualizer.
5
- *
6
- * Adapted from the `3d-effects-gallery` demo
7
- * (components/effects/WireOrbEffect.tsx). Plugs into
8
- * [`RealtimeCallOverlay`](./RealtimeCallOverlay.tsx:1) as the default
9
- * voice-call orb, replacing the previous R3F ripple
10
- * [`RealtimeOrb`](./RealtimeOrb.tsx:1). The two components share a
11
- * compatible public surface (state + analyser/level refs) so consumers
12
- * that imported `RealtimeOrb` directly can switch with a one-line edit.
13
- *
14
- * Public surface differences from the gallery source:
15
- *
16
- * - `state` accepts the realtime lifecycle phase
17
- * (`"idle" | "listening" | "speaking" | "connecting"`). Internally
18
- * mapped onto the demo's 4-state machine; `connecting` reuses
19
- * `thinking` motion.
20
- * - `levelRef` (optional) — mutable 0..1 audio level from
21
- * [`useRealtimeCall`](../hooks/useRealtimeCall.ts:1). When present
22
- * it boosts speak/listen amplitude so the orb pulses on actual
23
- * voice rather than the synthetic 5.5Hz heartbeat.
24
- * - `inputAnalyser` / `outputAnalyser` — accepted for API parity with
25
- * the old `RealtimeOrb`. Currently unused; the orb consumes the
26
- * pre-mixed `levelRef` instead.
27
- *
28
- * `three` is a PEER dependency of `@tinyweb-agent-framework/chat-ui`.
29
- * Hosts that import this orb must install `three` >= 0.160.
30
- */
31
-
32
- import { useEffect, useRef } from "react"
33
- import * as THREE from "three"
34
-
35
- export type WireOrbState = "idle" | "listening" | "thinking" | "speaking" | "connecting"
36
-
37
- export type WireOrbEffectProps = {
38
- readonly state: WireOrbState
39
- /** Audio level ref (0..1). Boosts speak/listen amplitude when present. */
40
- readonly levelRef?: { readonly current: number }
41
- /** Accepted for API parity with `RealtimeOrb`. Not yet consumed. */
42
- readonly inputAnalyser?: AnalyserNode | null
43
- /** Accepted for API parity with `RealtimeOrb`. Not yet consumed. */
44
- readonly outputAnalyser?: AnalyserNode | null
45
- /** Enable mouse-driven distortion (off in the call overlay by default). */
46
- readonly mouseEnabled?: boolean
47
- }
48
-
49
- // 3D simplex noise (Stefan Gustavson).
50
- const NOISE_GLSL = /* glsl */ `
51
- vec3 mod289(vec3 x){return x-floor(x*(1.0/289.0))*289.0;}
52
- vec4 mod289(vec4 x){return x-floor(x*(1.0/289.0))*289.0;}
53
- vec4 permute(vec4 x){return mod289(((x*34.0)+1.0)*x);}
54
- vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}
55
- float snoise(vec3 v){
56
- const vec2 C = vec2(1.0/6.0, 1.0/3.0);
57
- const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
58
- vec3 i = floor(v + dot(v, C.yyy));
59
- vec3 x0 = v - i + dot(i, C.xxx);
60
- vec3 g = step(x0.yzx, x0.xyz);
61
- vec3 l = 1.0 - g;
62
- vec3 i1 = min(g.xyz, l.zxy);
63
- vec3 i2 = max(g.xyz, l.zxy);
64
- vec3 x1 = x0 - i1 + C.xxx;
65
- vec3 x2 = x0 - i2 + C.yyy;
66
- vec3 x3 = x0 - D.yyy;
67
- i = mod289(i);
68
- vec4 p = permute( permute( permute(
69
- i.z + vec4(0.0, i1.z, i2.z, 1.0))
70
- + i.y + vec4(0.0, i1.y, i2.y, 1.0))
71
- + i.x + vec4(0.0, i1.x, i2.x, 1.0));
72
- float n_ = 0.142857142857;
73
- vec3 ns = n_ * D.wyz - D.xzx;
74
- vec4 j = p - 49.0 * floor(p * ns.z * ns.z);
75
- vec4 x_ = floor(j * ns.z);
76
- vec4 y_ = floor(j - 7.0 * x_);
77
- vec4 x = x_ *ns.x + ns.yyyy;
78
- vec4 y = y_ *ns.x + ns.yyyy;
79
- vec4 h = 1.0 - abs(x) - abs(y);
80
- vec4 b0 = vec4(x.xy, y.xy);
81
- vec4 b1 = vec4(x.zw, y.zw);
82
- vec4 s0 = floor(b0)*2.0 + 1.0;
83
- vec4 s1 = floor(b1)*2.0 + 1.0;
84
- vec4 sh = -step(h, vec4(0.0));
85
- vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy;
86
- vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww;
87
- vec3 p0 = vec3(a0.xy, h.x);
88
- vec3 p1 = vec3(a0.zw, h.y);
89
- vec3 p2 = vec3(a1.xy, h.z);
90
- vec3 p3 = vec3(a1.zw, h.w);
91
- vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2,p2), dot(p3,p3)));
92
- p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;
93
- vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
94
- m = m*m;
95
- return 42.0 * dot(m*m, vec4(dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3)));
96
- }
97
- float hash13(vec3 p){
98
- return fract(sin(dot(p, vec3(12.9898, 78.233, 45.164))) * 43758.5453);
99
- }
100
- `
101
-
102
- const STATE_UNIFORMS = /* glsl */ `
103
- uniform float wIdle;
104
- uniform float wListen;
105
- uniform float wThink;
106
- uniform float wSpeak;
107
- uniform float uTime;
108
- uniform float uFreq;
109
- uniform float uDistortBase;
110
- uniform float uLevel; // 0..1 external audio level
111
- uniform vec3 uMouseDir;
112
- uniform float uMouseStrength;
113
- `
114
-
115
- const WIRE_VERT = /* glsl */ `
116
- ${NOISE_GLSL}
117
- ${STATE_UNIFORMS}
118
- varying float vDist;
119
- varying float vGlow;
120
- void main(){
121
- vec3 p = position;
122
- vec3 nrm = normalize(p);
123
- float t = uTime * 0.55;
124
- float n = snoise(p * uFreq + vec3(0.0, t, 0.0)) * 0.6
125
- + snoise(p * uFreq * 2.1 + vec3(t*0.7, 0.0, t)) * 0.4;
126
-
127
- float idleD = 0.08 * sin(uTime * 1.1) + n * 0.10;
128
- float lat = nrm.y;
129
- float listenD = 0.05 + (0.10 + uLevel * 0.30) * sin(uTime * 2.8 - lat * 4.0) + n * 0.12;
130
- float hh = hash13(floor(p * 1.6));
131
- float gph = fract(hh + uTime * 0.30);
132
- float glitch = smoothstep(0.55, 0.85, gph) * smoothstep(1.00, 0.85, gph) * 0.04;
133
- float thinkD = n * 0.09 + glitch;
134
- // speaking: rhythmic radial heartbeat. Baseline matches the gallery
135
- // sample (beat * 0.14); uLevel adds a small audio-reactive lift but
136
- // capped low to avoid the orb ballooning past the viewport.
137
- float beat = pow(0.5 + 0.5 * sin(uTime * 5.5), 5.0);
138
- float speakD = beat * (0.14 + uLevel * 0.10) + n * 0.14;
139
-
140
- float d = uDistortBase
141
- + idleD * wIdle
142
- + listenD * wListen
143
- + thinkD * wThink
144
- + speakD * wSpeak;
145
-
146
- vec3 tang = normalize(cross(nrm, vec3(0.0, 1.0, 0.0001)));
147
- vec3 streak = tang * (wSpeak * 0.08 * sin(uTime * 4.0 + n * 3.0));
148
-
149
- float mDot = clamp(dot(nrm, uMouseDir), -1.0, 1.0);
150
- float mFall = pow(max(mDot, 0.0), 6.0);
151
- float mouseBump = uMouseStrength * mFall * 0.35;
152
- d += mouseBump;
153
-
154
- vec3 np = p + nrm * d + streak;
155
-
156
- vDist = d;
157
- vGlow = wThink * glitch * 0.5 + wSpeak * beat * 0.5 + wListen * 0.2
158
- + uMouseStrength * mFall * 0.6;
159
- gl_Position = projectionMatrix * modelViewMatrix * vec4(np, 1.0);
160
- }
161
- `
162
- const WIRE_FRAG = /* glsl */ `
163
- uniform vec3 uColor;
164
- uniform float uIntensity;
165
- varying float vDist;
166
- varying float vGlow;
167
- void main(){
168
- float k = 0.45 + 0.25 * (vDist + 0.5);
169
- vec3 col = uColor * k * uIntensity;
170
- gl_FragColor = vec4(min(col, vec3(0.85)), 1.0);
171
- }
172
- `
173
-
174
- const DUST_VERT = /* glsl */ `
175
- ${NOISE_GLSL}
176
- ${STATE_UNIFORMS}
177
- uniform float uResHeight;
178
- attribute float aSize;
179
- attribute float aOffset;
180
- attribute float aPhase;
181
- varying float vAlpha;
182
- varying float vBoost;
183
-
184
- mat3 rotY(float a){ return mat3(cos(a),0.,-sin(a), 0.,1.,0., sin(a),0.,cos(a)); }
185
-
186
- void main(){
187
- vec3 p = position;
188
- vec3 nrm = normalize(p);
189
- float t = uTime * 0.55;
190
- float n = snoise(p * uFreq + vec3(0.0, t, 0.0)) * 0.6
191
- + snoise(p * uFreq * 2.1 + vec3(t*0.7, 0.0, t)) * 0.4;
192
- float d = uDistortBase + n * 0.12;
193
-
194
- float idleR = 0.05 + 0.55 * aOffset * (0.6 + 0.4 * sin(uTime * 0.6 + aPhase * 6.28));
195
- float pull = mix(1.0, 0.05, aOffset);
196
- float sonar = 0.12 * sin(uTime * 3.5 - aOffset * 8.0);
197
- float listenR = 0.02 + pull * 0.08 + sonar * aOffset;
198
-
199
- float angle = uTime * (0.8 + aPhase * 2.5);
200
- vec3 pSpiral = rotY(angle) * p;
201
- float thinkR = 0.18 * aOffset + 0.08 * sin(uTime * 1.6 + aPhase * 6.28);
202
-
203
- // speaking: heartbeat radial BURST outward. Sample baseline is
204
- // aOffset * (0.25 + 0.40 * beat); we keep that and only let uLevel
205
- // add a gentle extra burst so loud audio doesn't blow the dust shell
206
- // way past the wireframe.
207
- float beat = pow(0.5 + 0.5 * sin(uTime * 5.5), 4.0);
208
- float speakR = aOffset * (0.25 + 0.40 * beat + uLevel * 0.20);
209
-
210
- float radial = idleR * wIdle
211
- + listenR * wListen
212
- + thinkR * wThink
213
- + speakR * wSpeak;
214
-
215
- vec3 pBase = mix(p, pSpiral, wThink);
216
- vec3 nrmB = normalize(pBase);
217
-
218
- float mDotD = clamp(dot(nrmB, uMouseDir), -1.0, 1.0);
219
- float mFallD = pow(max(mDotD, 0.0), 4.0);
220
- float mouseAttract = uMouseStrength * mFallD * aOffset * 0.55;
221
- float sparkle = uMouseStrength * pow(max(mDotD, 0.0), 24.0) * 0.4;
222
-
223
- vec3 np = pBase + nrmB * (d + radial - mouseAttract + sparkle);
224
-
225
- // Dust point-size boost. Sample uses wSpeak * beat * 1.0; we add a
226
- // small uLevel contribution for liveliness but clamp it well below
227
- // the radial burst so loud audio doesn't make every dust point huge.
228
- float boost = 1.0
229
- + wSpeak * (beat + uLevel * 0.4) * 1.0
230
- + wListen * max(0.0, sonar) * 1.5
231
- + wThink * step(0.9, fract(aPhase + uTime * 0.3)) * 1.2
232
- + uMouseStrength * mFallD * 2.5;
233
-
234
- vec4 mv = modelViewMatrix * vec4(np, 1.0);
235
- gl_Position = projectionMatrix * mv;
236
- // Point size is normalised by canvas height (uResHeight) against a 680px
237
- // reference (the orb max CSS size) and then hard-clamped. Without the
238
- // normalisation the raw 140.0 / -mv.z term yields a fixed pixel size
239
- // regardless of resolution, so on large / high-DPI canvases the additive
240
- // dust points overlap far more per output pixel and bloom into a blown-out
241
- // glare. Normalising + clamping keeps the dust coverage — and therefore the
242
- // additive brightness — visually constant on every screen. This is the only
243
- // change needed for the large-screen blow-out; density/alpha stay original.
244
- float sizeScale = uResHeight / 680.0;
245
- float ps = aSize * boost * (140.0 / -mv.z) * sizeScale;
246
- gl_PointSize = clamp(ps, 1.0, 12.0);
247
-
248
- vAlpha = 1.0 - aOffset * 0.5;
249
- vBoost = boost;
250
- }
251
- `
252
- const DUST_FRAG = /* glsl */ `
253
- uniform vec3 uColor;
254
- uniform float uIntensity;
255
- varying float vAlpha;
256
- varying float vBoost;
257
- void main(){
258
- vec2 c = gl_PointCoord - 0.5;
259
- float d = length(c);
260
- float a = pow(smoothstep(0.5, 0.0, d), 1.6);
261
- vec3 col = uColor * uIntensity * 0.55;
262
- gl_FragColor = vec4(col, a * vAlpha * 0.7);
263
- }
264
- `
265
-
266
- const COLOR_MONO: [number, number, number] = [0.92, 0.95, 1.0]
267
- const COLOR_LISTEN: [number, number, number] = [0.35, 1.0, 0.6]
268
- const COLOR_SPEAK: [number, number, number] = [0.2, 0.55, 1.0]
269
- const COLOR_THINK: [number, number, number] = [1.0, 0.75, 0.2]
270
-
271
- const mapState = (
272
- s: WireOrbState,
273
- ): "idle" | "listening" | "thinking" | "speaking" => {
274
- // `connecting` reuses idle motion + colour so the boot phase reads
275
- // as the demo's idle (icy monochrome breath). Matches the standalone
276
- // gallery preview at /wire-orb where idle is the default.
277
- if (s === "connecting") return "idle"
278
- return s
279
- }
280
-
281
- export const WireOrbEffect = (props: WireOrbEffectProps) => {
282
- const { state, levelRef, mouseEnabled = false } = props
283
- const mountRef = useRef<HTMLDivElement>(null)
284
- const stateRef = useRef<WireOrbState>(state)
285
- stateRef.current = state
286
- const mouseEnabledRef = useRef<boolean>(mouseEnabled)
287
- mouseEnabledRef.current = mouseEnabled
288
- const externalLevelRef = levelRef
289
-
290
- useEffect(() => {
291
- const mount = mountRef.current
292
- if (!mount) return
293
- const W = mount.clientWidth || 320
294
- const H = mount.clientHeight || 320
295
-
296
- const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true })
297
- renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
298
- renderer.setSize(W, H)
299
- renderer.setClearColor(0x000000, 0)
300
- mount.appendChild(renderer.domElement)
301
-
302
- const scene = new THREE.Scene()
303
- const cam = new THREE.PerspectiveCamera(45, W / H, 0.1, 100)
304
- cam.position.set(0, 0, 5)
305
-
306
- const sphereGeo = new THREE.IcosahedronGeometry(1.0, 12)
307
- const wireGeo = new THREE.WireframeGeometry(sphereGeo)
308
- const sharedUniforms = {
309
- wIdle: { value: 1 },
310
- wListen: { value: 0 },
311
- wThink: { value: 0 },
312
- wSpeak: { value: 0 },
313
- uTime: { value: 0 },
314
- uFreq: { value: 1.6 },
315
- uDistortBase: { value: 0.08 },
316
- uLevel: { value: 0 },
317
- uMouseDir: { value: new THREE.Vector3(0, 0, 1) },
318
- uMouseStrength: { value: 0 },
319
- }
320
- const wireMat = new THREE.ShaderMaterial({
321
- vertexShader: WIRE_VERT,
322
- fragmentShader: WIRE_FRAG,
323
- uniforms: {
324
- ...sharedUniforms,
325
- uColor: { value: new THREE.Color().fromArray(COLOR_MONO) },
326
- uIntensity: { value: 0.7 },
327
- },
328
- transparent: true,
329
- })
330
- const wire = new THREE.LineSegments(wireGeo, wireMat)
331
- scene.add(wire)
332
-
333
- const COUNT = 4500
334
- const positions = new Float32Array(COUNT * 3)
335
- const sizes = new Float32Array(COUNT)
336
- const offsets = new Float32Array(COUNT)
337
- const phases = new Float32Array(COUNT)
338
- for (let i = 0; i < COUNT; i++) {
339
- const th = Math.acos(2 * Math.random() - 1)
340
- const ph = Math.random() * Math.PI * 2
341
- positions[i * 3 + 0] = Math.sin(th) * Math.cos(ph)
342
- positions[i * 3 + 1] = Math.cos(th)
343
- positions[i * 3 + 2] = Math.sin(th) * Math.sin(ph)
344
- sizes[i] = 0.35 + Math.random() * 0.9
345
- offsets[i] =
346
- Math.random() < 0.3 ? Math.random() * 0.08 : 0.1 + Math.random() * 0.95
347
- phases[i] = Math.random()
348
- }
349
- const dustGeo = new THREE.BufferGeometry()
350
- dustGeo.setAttribute("position", new THREE.BufferAttribute(positions, 3))
351
- dustGeo.setAttribute("aSize", new THREE.BufferAttribute(sizes, 1))
352
- dustGeo.setAttribute("aOffset", new THREE.BufferAttribute(offsets, 1))
353
- dustGeo.setAttribute("aPhase", new THREE.BufferAttribute(phases, 1))
354
-
355
- const dustUniforms = {
356
- wIdle: sharedUniforms.wIdle,
357
- wListen: sharedUniforms.wListen,
358
- wThink: sharedUniforms.wThink,
359
- wSpeak: sharedUniforms.wSpeak,
360
- uTime: sharedUniforms.uTime,
361
- uFreq: sharedUniforms.uFreq,
362
- uDistortBase: sharedUniforms.uDistortBase,
363
- uLevel: sharedUniforms.uLevel,
364
- uMouseDir: sharedUniforms.uMouseDir,
365
- uMouseStrength: sharedUniforms.uMouseStrength,
366
- uColor: { value: new THREE.Color().fromArray(COLOR_MONO) },
367
- uIntensity: { value: 0.65 },
368
- uResHeight: { value: H },
369
- }
370
- const dustMat = new THREE.ShaderMaterial({
371
- vertexShader: DUST_VERT,
372
- fragmentShader: DUST_FRAG,
373
- uniforms: dustUniforms,
374
- transparent: true,
375
- depthWrite: false,
376
- blending: THREE.AdditiveBlending,
377
- })
378
- const dust = new THREE.Points(dustGeo, dustMat)
379
- scene.add(dust)
380
-
381
- const clock = new THREE.Clock()
382
- let raf = 0
383
- const lerp = (a: number, b: number, t: number) => a + (b - a) * t
384
- const lerpCol = (c: THREE.Color, t: [number, number, number], k: number) => {
385
- c.r = lerp(c.r, t[0], k)
386
- c.g = lerp(c.g, t[1], k)
387
- c.b = lerp(c.b, t[2], k)
388
- }
389
-
390
- const ndc = new THREE.Vector2(0, 0)
391
- const ndcSmooth = new THREE.Vector2(0, 0)
392
- let mouseInside = false
393
- const raycaster = new THREE.Raycaster()
394
- const sphereForHit = new THREE.Sphere(new THREE.Vector3(0, 0, 0), 1.0)
395
- const tmpHit = new THREE.Vector3()
396
- const mouseDirTarget = new THREE.Vector3(0, 0, 1)
397
-
398
- const onMouseMove = (e: MouseEvent) => {
399
- const rect = renderer.domElement.getBoundingClientRect()
400
- ndc.x = ((e.clientX - rect.left) / rect.width) * 2 - 1
401
- ndc.y = -((e.clientY - rect.top) / rect.height) * 2 + 1
402
- mouseInside = true
403
- }
404
- const onMouseLeave = () => {
405
- mouseInside = false
406
- }
407
- renderer.domElement.addEventListener("mousemove", onMouseMove)
408
- renderer.domElement.addEventListener("mouseleave", onMouseLeave)
409
-
410
- function tick() {
411
- const dt = clock.getDelta()
412
- const t = clock.getElapsedTime()
413
- sharedUniforms.uTime.value = t
414
-
415
- // NOTE: `listening` reuses the IDLE motion (same weight + freq); only
416
- // the color tint differs. This matches the gallery sample where
417
- // listening is a green-tinted idle orb rather than a sonar wave +
418
- // dust pull-in.
419
- const s = mapState(stateRef.current)
420
- const tgI = s === "idle" || s === "listening" ? 1 : 0
421
- const tgL = 0
422
- const tgT = s === "thinking" ? 1 : 0
423
- const tgS = s === "speaking" ? 1 : 0
424
- const k = Math.min(dt * 3.0, 1)
425
- sharedUniforms.wIdle.value = lerp(sharedUniforms.wIdle.value, tgI, k)
426
- sharedUniforms.wListen.value = lerp(sharedUniforms.wListen.value, tgL, k)
427
- sharedUniforms.wThink.value = lerp(sharedUniforms.wThink.value, tgT, k)
428
- sharedUniforms.wSpeak.value = lerp(sharedUniforms.wSpeak.value, tgS, k)
429
-
430
- const tgFreq = s === "thinking" ? 1.5 : s === "speaking" ? 1.8 : 1.5
431
- sharedUniforms.uFreq.value = lerp(sharedUniforms.uFreq.value, tgFreq, k)
432
-
433
- const rawLvl = externalLevelRef
434
- ? Math.max(0, Math.min(1, externalLevelRef.current || 0))
435
- : 0
436
- sharedUniforms.uLevel.value = lerp(
437
- sharedUniforms.uLevel.value,
438
- rawLvl,
439
- Math.min(dt * 8.0, 1),
440
- )
441
-
442
- const tgColor =
443
- s === "listening" ? COLOR_LISTEN :
444
- s === "speaking" ? COLOR_SPEAK :
445
- s === "thinking" ? COLOR_THINK :
446
- COLOR_MONO
447
- lerpCol(wireMat.uniforms.uColor.value, tgColor, k)
448
- lerpCol(dustUniforms.uColor.value, tgColor, k)
449
-
450
- const tgIntWire = s === "speaking" ? 0.78 : 0.7
451
- const tgIntDust = s === "speaking" ? 0.72 : 0.65
452
- wireMat.uniforms.uIntensity.value = lerp(
453
- wireMat.uniforms.uIntensity.value,
454
- tgIntWire,
455
- k,
456
- )
457
- dustUniforms.uIntensity.value = lerp(
458
- dustUniforms.uIntensity.value,
459
- tgIntDust,
460
- k,
461
- )
462
-
463
- const mk = Math.min(dt * 6.0, 1)
464
- ndcSmooth.x = lerp(ndcSmooth.x, ndc.x, mk)
465
- ndcSmooth.y = lerp(ndcSmooth.y, ndc.y, mk)
466
-
467
- const wantMouse = mouseEnabledRef.current && mouseInside ? 1 : 0
468
- sharedUniforms.uMouseStrength.value = lerp(
469
- sharedUniforms.uMouseStrength.value,
470
- wantMouse,
471
- Math.min(dt * 4.0, 1),
472
- )
473
-
474
- if (mouseEnabledRef.current) {
475
- raycaster.setFromCamera(ndcSmooth, cam)
476
- const hit = raycaster.ray.intersectSphere(sphereForHit, tmpHit)
477
- if (hit) {
478
- mouseDirTarget.copy(hit).normalize()
479
- } else {
480
- raycaster.ray.at(4, tmpHit)
481
- mouseDirTarget.copy(tmpHit).normalize()
482
- }
483
- const inv = new THREE.Matrix4().copy(wire.matrixWorld).invert()
484
- const localDir = mouseDirTarget.clone().applyMatrix4(inv).normalize()
485
- const cur = sharedUniforms.uMouseDir.value as THREE.Vector3
486
- cur.lerp(localDir, Math.min(dt * 5.0, 1)).normalize()
487
- }
488
-
489
- const tgZ = s === "listening" ? 4.2 : s === "speaking" ? 4.6 : 5.0
490
- cam.position.z = lerp(cam.position.z, tgZ, dt * 1.5)
491
- const shake = s === "speaking" ? Math.sin(t * 30.0) * 0.025 : 0
492
- const ms = sharedUniforms.uMouseStrength.value
493
- const targetX = shake + ndcSmooth.x * 0.35 * ms
494
- const targetY =
495
- (s === "speaking" ? Math.cos(t * 28.0) * 0.02 : 0) + ndcSmooth.y * 0.25 * ms
496
- cam.position.x = lerp(cam.position.x, targetX, 0.4)
497
- cam.position.y = lerp(cam.position.y, targetY, 0.4)
498
- cam.lookAt(0, 0, 0)
499
-
500
- const rotSpeed =
501
- s === "thinking" ? 0.6 :
502
- s === "speaking" ? 0.35 :
503
- s === "listening" ? 0.12 :
504
- 0.18
505
- wire.rotation.y += dt * rotSpeed
506
- const tiltY = ndcSmooth.x * 0.35 * ms
507
- const tiltX =
508
- -ndcSmooth.y * 0.25 * ms +
509
- Math.sin(t * 0.3) * (s === "thinking" ? 0.25 : 0.1)
510
- wire.rotation.x = lerp(wire.rotation.x, tiltX, 0.2)
511
- wire.rotation.z = lerp(wire.rotation.z, tiltY, 0.2)
512
- wire.updateMatrixWorld(true)
513
- dust.rotation.copy(wire.rotation)
514
-
515
- renderer.render(scene, cam)
516
- raf = requestAnimationFrame(tick)
517
- }
518
- tick()
519
-
520
- const onResize = () => {
521
- const Wn = mount.clientWidth || W
522
- const Hn = mount.clientHeight || H
523
- renderer.setSize(Wn, Hn)
524
- cam.aspect = Wn / Hn
525
- cam.updateProjectionMatrix()
526
- // Keep dust point-size coverage constant across screen sizes; see the
527
- // comment in DUST_VERT. uResHeight tracks the CSS height of the canvas.
528
- dustUniforms.uResHeight.value = Hn
529
- }
530
- window.addEventListener("resize", onResize)
531
- const ro = new ResizeObserver(onResize)
532
- ro.observe(mount)
533
-
534
- return () => {
535
- cancelAnimationFrame(raf)
536
- window.removeEventListener("resize", onResize)
537
- ro.disconnect()
538
- renderer.domElement.removeEventListener("mousemove", onMouseMove)
539
- renderer.domElement.removeEventListener("mouseleave", onMouseLeave)
540
- renderer.dispose()
541
- sphereGeo.dispose()
542
- wireGeo.dispose()
543
- wireMat.dispose()
544
- dustGeo.dispose()
545
- dustMat.dispose()
546
- if (renderer.domElement.parentElement === mount) {
547
- mount.removeChild(renderer.domElement)
548
- }
549
- }
550
- // eslint-disable-next-line react-hooks/exhaustive-deps
551
- }, [])
552
-
553
- return <div ref={mountRef} className="wire-orb-effect" />
554
- }
555
-
556
- export default WireOrbEffect
@@ -1,77 +0,0 @@
1
- import { useState } from "react"
2
- import type { CondenseState } from "../../types"
3
-
4
- export type CondensePillProps = {
5
- state: CondenseState
6
- }
7
-
8
- const fmt = (n: number): string => n.toLocaleString()
9
-
10
- const StartContent = (props: { state: Extract<CondenseState, { phase: "start" }> }) => {
11
- const overflow = props.state.trigger === "overflow-retry"
12
- const base = overflow ? "Context overflow — recovering…" : "Condensing context…"
13
- const stats =
14
- typeof props.state.estimatedTokens === "number" &&
15
- typeof props.state.budgetTokens === "number"
16
- ? " (" + fmt(props.state.estimatedTokens) + " tok > " + fmt(props.state.budgetTokens) + " budget)"
17
- : ""
18
- return <span>{base + stats}</span>
19
- }
20
-
21
- const SuccessContent = (props: { state: Extract<CondenseState, { phase: "success" }> }) => {
22
- const [open, setOpen] = useState(false)
23
- const s = props.state
24
- const hasTokens = typeof s.prevTokens === "number" && typeof s.newTokens === "number"
25
- return (
26
- <details
27
- open={open}
28
- onToggle={(e) => setOpen((e.currentTarget as HTMLDetailsElement).open)}
29
- >
30
- <summary>
31
- Context condensed
32
- {hasTokens ? (
33
- <>
34
- <span className="stat"> — {fmt(s.prevTokens ?? 0)} </span>
35
- <span className="arrow">→</span>
36
- <span className="stat"> {fmt(s.newTokens ?? 0)} tok</span>
37
- </>
38
- ) : null}
39
- {typeof s.cost === "number" && s.cost > 0 ? (
40
- <span className="stat"> · ${s.cost.toFixed(4)}</span>
41
- ) : null}
42
- {s.modelId ? <span className="arrow"> · {s.modelId}</span> : null}
43
- </summary>
44
- <div className="summary-body">{s.summary || "(no summary)"}</div>
45
- </details>
46
- )
47
- }
48
-
49
- const ErrorContent = (props: { state: Extract<CondenseState, { phase: "error" }> }) => (
50
- <span>
51
- {props.state.retryExhausted
52
- ? "Compaction retry exhausted — request can't fit the model context."
53
- : "Condense failed: " + (props.state.message || "(unknown)")}
54
- </span>
55
- )
56
-
57
- /**
58
- * Single pill that morphs through start → success | error states for one
59
- * condense trigger. Ported from [`app.js`](../../../../examples/device-pilot/public/app.js:343)
60
- * `renderCondenseStart` / `Success` / `Error`.
61
- */
62
- export const CondensePill = (props: CondensePillProps) => {
63
- const s = props.state
64
- const overflow = s.phase === "start" && s.trigger === "overflow-retry"
65
- const classes = ["condense"]
66
- if (overflow) classes.push("overflow")
67
- if (s.phase === "success") classes.push("done")
68
- if (s.phase === "error") classes.push("error")
69
- return (
70
- <div className={classes.join(" ")} data-testid="tinyweb-condense-pill" data-phase={s.phase}>
71
- <span className="dot" />
72
- {s.phase === "start" ? <StartContent state={s} /> : null}
73
- {s.phase === "success" ? <SuccessContent state={s} /> : null}
74
- {s.phase === "error" ? <ErrorContent state={s} /> : null}
75
- </div>
76
- )
77
- }
@@ -1,15 +0,0 @@
1
- import { renderMarkdown } from "../../markdown/render"
2
-
3
- export type AssistantMessageProps = { content: string }
4
-
5
- /**
6
- * Renders accumulated assistant text as markdown. The function escapes all
7
- * source before reintroducing safe markup, so `dangerouslySetInnerHTML`
8
- * here is safe by construction (see [`renderMarkdown`](../../markdown/render.ts)).
9
- */
10
- export const AssistantMessage = (props: AssistantMessageProps) => (
11
- <div className="msg assistant">
12
- <div className="role">assistant</div>
13
- <div className="body" dangerouslySetInnerHTML={{ __html: renderMarkdown(props.content) }} />
14
- </div>
15
- )
@@ -1,12 +0,0 @@
1
- export type ErrorMessageProps = {
2
- message: string
3
- /** Label override — e.g. "tool-error". Defaults to "error". */
4
- label?: string
5
- }
6
-
7
- export const ErrorMessage = (props: ErrorMessageProps) => (
8
- <div className="msg error">
9
- <div className="role">{props.label ?? "error"}</div>
10
- <div className="body">{props.message}</div>
11
- </div>
12
- )