@runtypelabs/persona 1.47.0 → 2.0.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 (73) hide show
  1. package/README.md +140 -8
  2. package/dist/index.cjs +90 -39
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +1093 -25
  5. package/dist/index.d.ts +1093 -25
  6. package/dist/index.global.js +111 -60
  7. package/dist/index.global.js.map +1 -1
  8. package/dist/index.js +90 -39
  9. package/dist/index.js.map +1 -1
  10. package/dist/install.global.js +1 -1
  11. package/dist/install.global.js.map +1 -1
  12. package/dist/widget.css +852 -505
  13. package/package.json +1 -1
  14. package/src/artifacts-session.test.ts +80 -0
  15. package/src/client.test.ts +20 -21
  16. package/src/client.ts +153 -4
  17. package/src/components/approval-bubble.ts +45 -42
  18. package/src/components/artifact-card.ts +91 -0
  19. package/src/components/artifact-pane.ts +501 -0
  20. package/src/components/composer-builder.ts +32 -27
  21. package/src/components/event-stream-view.ts +40 -40
  22. package/src/components/feedback.ts +36 -36
  23. package/src/components/forms.ts +11 -11
  24. package/src/components/header-builder.test.ts +32 -0
  25. package/src/components/header-builder.ts +55 -36
  26. package/src/components/header-layouts.ts +58 -125
  27. package/src/components/launcher.ts +36 -21
  28. package/src/components/message-bubble.ts +92 -65
  29. package/src/components/messages.ts +2 -2
  30. package/src/components/panel.ts +42 -11
  31. package/src/components/reasoning-bubble.ts +23 -23
  32. package/src/components/registry.ts +4 -0
  33. package/src/components/suggestions.ts +1 -1
  34. package/src/components/tool-bubble.ts +32 -32
  35. package/src/defaults.ts +30 -4
  36. package/src/index.ts +80 -2
  37. package/src/install.ts +22 -0
  38. package/src/plugins/types.ts +23 -0
  39. package/src/postprocessors.ts +2 -2
  40. package/src/runtime/host-layout.ts +174 -0
  41. package/src/runtime/init.test.ts +236 -0
  42. package/src/runtime/init.ts +114 -55
  43. package/src/session.ts +173 -7
  44. package/src/styles/tailwind.css +1 -1
  45. package/src/styles/widget.css +852 -505
  46. package/src/types/theme.ts +354 -0
  47. package/src/types.ts +348 -16
  48. package/src/ui.docked.test.ts +104 -0
  49. package/src/ui.ts +1093 -244
  50. package/src/utils/artifact-gate.test.ts +255 -0
  51. package/src/utils/artifact-gate.ts +142 -0
  52. package/src/utils/artifact-resize.test.ts +64 -0
  53. package/src/utils/artifact-resize.ts +67 -0
  54. package/src/utils/attachment-manager.ts +10 -10
  55. package/src/utils/code-generators.test.ts +52 -0
  56. package/src/utils/code-generators.ts +40 -36
  57. package/src/utils/dock.ts +17 -0
  58. package/src/utils/dom-context.test.ts +504 -0
  59. package/src/utils/dom-context.ts +896 -0
  60. package/src/utils/dom.ts +12 -1
  61. package/src/utils/message-fingerprint.test.ts +187 -0
  62. package/src/utils/message-fingerprint.ts +105 -0
  63. package/src/utils/migration.ts +179 -0
  64. package/src/utils/morph.ts +1 -1
  65. package/src/utils/plugins.ts +175 -0
  66. package/src/utils/positioning.ts +4 -4
  67. package/src/utils/theme.test.ts +125 -0
  68. package/src/utils/theme.ts +216 -60
  69. package/src/utils/tokens.ts +682 -0
  70. package/src/voice/audio-playback-manager.ts +187 -0
  71. package/src/voice/runtype-voice-provider.ts +305 -69
  72. package/src/voice/voice-activity-detector.ts +90 -0
  73. package/src/voice/voice.test.ts +6 -5
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Voice Activity Detector (VAD)
3
+ *
4
+ * Reusable RMS-based voice activity detection that monitors a mic stream
5
+ * and fires a callback when a condition is sustained for a given duration.
6
+ *
7
+ * - mode 'silence': fires when volume stays below threshold (user stopped talking)
8
+ * - mode 'speech': fires when volume stays above threshold (user started talking)
9
+ *
10
+ * Fires callback exactly once per start() call, then stops checking.
11
+ * Calling start() again implicitly calls stop() first.
12
+ */
13
+ export class VoiceActivityDetector {
14
+ private sourceNode: MediaStreamAudioSourceNode | null = null;
15
+ private analyserNode: AnalyserNode | null = null;
16
+ private interval: ReturnType<typeof setInterval> | null = null;
17
+ private conditionStart: number | null = null;
18
+ private fired = false;
19
+
20
+ /**
21
+ * Begin monitoring the given stream for voice activity.
22
+ *
23
+ * @param audioContext Active AudioContext
24
+ * @param stream MediaStream from getUserMedia
25
+ * @param mode 'silence' fires when quiet for duration, 'speech' fires when loud for duration
26
+ * @param config threshold (RMS level) and duration (ms)
27
+ * @param callback Fires exactly once when the condition is met
28
+ */
29
+ start(
30
+ audioContext: AudioContext,
31
+ stream: MediaStream,
32
+ mode: "silence" | "speech",
33
+ config: { threshold: number; duration: number },
34
+ callback: () => void,
35
+ ): void {
36
+ this.stop();
37
+
38
+ this.fired = false;
39
+ this.conditionStart = null;
40
+
41
+ this.sourceNode = audioContext.createMediaStreamSource(stream);
42
+ this.analyserNode = audioContext.createAnalyser();
43
+ this.analyserNode.fftSize = 2048;
44
+ this.sourceNode.connect(this.analyserNode);
45
+
46
+ const dataArray = new Float32Array(this.analyserNode.fftSize);
47
+
48
+ this.interval = setInterval(() => {
49
+ if (!this.analyserNode || this.fired) return;
50
+ this.analyserNode.getFloatTimeDomainData(dataArray);
51
+
52
+ // Compute RMS volume
53
+ let sum = 0;
54
+ for (let i = 0; i < dataArray.length; i++) {
55
+ sum += dataArray[i] * dataArray[i];
56
+ }
57
+ const rms = Math.sqrt(sum / dataArray.length);
58
+
59
+ const conditionMet =
60
+ mode === "silence"
61
+ ? rms < config.threshold
62
+ : rms >= config.threshold;
63
+
64
+ if (conditionMet) {
65
+ if (this.conditionStart === null) {
66
+ this.conditionStart = Date.now();
67
+ } else if (Date.now() - this.conditionStart >= config.duration) {
68
+ this.fired = true;
69
+ callback();
70
+ }
71
+ } else {
72
+ this.conditionStart = null;
73
+ }
74
+ }, 100);
75
+ }
76
+
77
+ stop(): void {
78
+ if (this.interval) {
79
+ clearInterval(this.interval);
80
+ this.interval = null;
81
+ }
82
+ if (this.sourceNode) {
83
+ this.sourceNode.disconnect();
84
+ this.sourceNode = null;
85
+ }
86
+ this.analyserNode = null;
87
+ this.conditionStart = null;
88
+ this.fired = false;
89
+ }
90
+ }
@@ -1,12 +1,13 @@
1
1
  // Voice SDK Tests
2
- import { describe, it, expect, vi, beforeEach, beforeAll, afterAll } from 'vitest';
3
- import { VoiceProvider, VoiceResult, VoiceStatus, VoiceConfig } from './provider-interface';
2
+ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
3
+ import type { VoiceConfig } from '../types';
4
4
  import { RuntypeVoiceProvider } from './runtype-voice-provider';
5
5
  import { BrowserVoiceProvider } from './browser-voice-provider';
6
6
  import { createVoiceProvider, createBestAvailableVoiceProvider, isVoiceSupported } from './voice-factory';
7
7
 
8
8
  // Mock window object for browser tests
9
- const mockWindow = {
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const mockWindow: any = {
10
11
  SpeechRecognition: undefined,
11
12
  webkitSpeechRecognition: undefined
12
13
  };
@@ -160,7 +161,7 @@ describe('Best Available Voice Provider', () => {
160
161
  mockBrowserSupport(false);
161
162
 
162
163
  const config = {
163
- type: 'runtype',
164
+ type: 'runtype' as const,
164
165
  runtype: {
165
166
  agentId: 'test-agent',
166
167
  clientToken: 'test-token'
@@ -200,7 +201,7 @@ describe('Voice Support Check', () => {
200
201
  mockBrowserSupport(false);
201
202
 
202
203
  const config = {
203
- type: 'runtype',
204
+ type: 'runtype' as const,
204
205
  runtype: {
205
206
  agentId: 'test-agent',
206
207
  clientToken: 'test-token'