@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.
- package/README.md +140 -8
- package/dist/index.cjs +90 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1093 -25
- package/dist/index.d.ts +1093 -25
- package/dist/index.global.js +111 -60
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +90 -39
- package/dist/index.js.map +1 -1
- package/dist/install.global.js +1 -1
- package/dist/install.global.js.map +1 -1
- package/dist/widget.css +852 -505
- package/package.json +1 -1
- package/src/artifacts-session.test.ts +80 -0
- package/src/client.test.ts +20 -21
- package/src/client.ts +153 -4
- package/src/components/approval-bubble.ts +45 -42
- package/src/components/artifact-card.ts +91 -0
- package/src/components/artifact-pane.ts +501 -0
- package/src/components/composer-builder.ts +32 -27
- package/src/components/event-stream-view.ts +40 -40
- package/src/components/feedback.ts +36 -36
- package/src/components/forms.ts +11 -11
- package/src/components/header-builder.test.ts +32 -0
- package/src/components/header-builder.ts +55 -36
- package/src/components/header-layouts.ts +58 -125
- package/src/components/launcher.ts +36 -21
- package/src/components/message-bubble.ts +92 -65
- package/src/components/messages.ts +2 -2
- package/src/components/panel.ts +42 -11
- package/src/components/reasoning-bubble.ts +23 -23
- package/src/components/registry.ts +4 -0
- package/src/components/suggestions.ts +1 -1
- package/src/components/tool-bubble.ts +32 -32
- package/src/defaults.ts +30 -4
- package/src/index.ts +80 -2
- package/src/install.ts +22 -0
- package/src/plugins/types.ts +23 -0
- package/src/postprocessors.ts +2 -2
- package/src/runtime/host-layout.ts +174 -0
- package/src/runtime/init.test.ts +236 -0
- package/src/runtime/init.ts +114 -55
- package/src/session.ts +173 -7
- package/src/styles/tailwind.css +1 -1
- package/src/styles/widget.css +852 -505
- package/src/types/theme.ts +354 -0
- package/src/types.ts +348 -16
- package/src/ui.docked.test.ts +104 -0
- package/src/ui.ts +1093 -244
- package/src/utils/artifact-gate.test.ts +255 -0
- package/src/utils/artifact-gate.ts +142 -0
- package/src/utils/artifact-resize.test.ts +64 -0
- package/src/utils/artifact-resize.ts +67 -0
- package/src/utils/attachment-manager.ts +10 -10
- package/src/utils/code-generators.test.ts +52 -0
- package/src/utils/code-generators.ts +40 -36
- package/src/utils/dock.ts +17 -0
- package/src/utils/dom-context.test.ts +504 -0
- package/src/utils/dom-context.ts +896 -0
- package/src/utils/dom.ts +12 -1
- package/src/utils/message-fingerprint.test.ts +187 -0
- package/src/utils/message-fingerprint.ts +105 -0
- package/src/utils/migration.ts +179 -0
- package/src/utils/morph.ts +1 -1
- package/src/utils/plugins.ts +175 -0
- package/src/utils/positioning.ts +4 -4
- package/src/utils/theme.test.ts +125 -0
- package/src/utils/theme.ts +216 -60
- package/src/utils/tokens.ts +682 -0
- package/src/voice/audio-playback-manager.ts +187 -0
- package/src/voice/runtype-voice-provider.ts +305 -69
- package/src/voice/voice-activity-detector.ts +90 -0
- 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
|
+
}
|
package/src/voice/voice.test.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Voice SDK Tests
|
|
2
|
-
import { describe, it, expect,
|
|
3
|
-
import {
|
|
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
|
-
|
|
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'
|