@formmy.app/chat 0.0.4 → 0.0.5
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.
|
@@ -31,11 +31,16 @@ import { type VoiceStatus, type VoiceTranscript } from "../voice/voice-client";
|
|
|
31
31
|
export interface UseFormmyVoiceOptions {
|
|
32
32
|
agentId: string;
|
|
33
33
|
voiceId?: string;
|
|
34
|
+
onStatusChange?: (status: VoiceStatus) => void;
|
|
35
|
+
onError?: (error: Error) => void;
|
|
36
|
+
onTranscript?: (transcript: VoiceTranscript) => void;
|
|
34
37
|
}
|
|
35
38
|
export interface UseFormmyVoiceReturn {
|
|
36
39
|
start: () => Promise<void>;
|
|
37
40
|
stop: () => void;
|
|
38
41
|
toggleMute: () => void;
|
|
42
|
+
setMuted: (muted: boolean) => void;
|
|
43
|
+
clearTranscripts: () => void;
|
|
39
44
|
status: VoiceStatus;
|
|
40
45
|
isMuted: boolean;
|
|
41
46
|
isSpeaking: boolean;
|
|
@@ -43,5 +48,5 @@ export interface UseFormmyVoiceReturn {
|
|
|
43
48
|
error: Error | null;
|
|
44
49
|
transcripts: VoiceTranscript[];
|
|
45
50
|
}
|
|
46
|
-
export declare function useFormmyVoice({ agentId, voiceId }: UseFormmyVoiceOptions): UseFormmyVoiceReturn;
|
|
51
|
+
export declare function useFormmyVoice({ agentId, voiceId, onStatusChange: onStatusChangeCb, onError: onErrorCb, onTranscript: onTranscriptCb }: UseFormmyVoiceOptions): UseFormmyVoiceReturn;
|
|
47
52
|
//# sourceMappingURL=use-formmy-voice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-formmy-voice.d.ts","sourceRoot":"","sources":["../../src/hooks/use-formmy-voice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,EAAqB,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAElG,MAAM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@ -30,7 +30,7 @@
|
|
|
30
30
|
import { useState, useRef, useCallback, useEffect } from "react";
|
|
31
31
|
import { useFormmy } from "../ui/provider";
|
|
32
32
|
import { FormmyVoiceClient } from "../voice/voice-client";
|
|
33
|
-
export function useFormmyVoice({ agentId, voiceId }) {
|
|
33
|
+
export function useFormmyVoice({ agentId, voiceId, onStatusChange: onStatusChangeCb, onError: onErrorCb, onTranscript: onTranscriptCb }) {
|
|
34
34
|
const { publishableKey, baseUrl } = useFormmy();
|
|
35
35
|
const clientRef = useRef(null);
|
|
36
36
|
const [status, setStatus] = useState("idle");
|
|
@@ -58,14 +58,16 @@ export function useFormmyVoice({ agentId, voiceId }) {
|
|
|
58
58
|
voiceId,
|
|
59
59
|
});
|
|
60
60
|
client.on({
|
|
61
|
-
onStatusChange: (s) =>
|
|
61
|
+
onStatusChange: (s) => {
|
|
62
|
+
setStatus(s);
|
|
63
|
+
onStatusChangeCb?.(s);
|
|
64
|
+
},
|
|
62
65
|
onTranscript: (t) => {
|
|
66
|
+
onTranscriptCb?.(t);
|
|
63
67
|
setTranscripts((prev) => {
|
|
64
68
|
if (t.isFinal) {
|
|
65
|
-
// Add as final entry
|
|
66
69
|
return [...prev, t];
|
|
67
70
|
}
|
|
68
|
-
// Update last entry of same role if it's a partial
|
|
69
71
|
const last = prev[prev.length - 1];
|
|
70
72
|
if (last && last.role === t.role && !last.isFinal) {
|
|
71
73
|
return [...prev.slice(0, -1), t];
|
|
@@ -73,13 +75,16 @@ export function useFormmyVoice({ agentId, voiceId }) {
|
|
|
73
75
|
return [...prev, t];
|
|
74
76
|
});
|
|
75
77
|
},
|
|
76
|
-
onError: (err) =>
|
|
78
|
+
onError: (err) => {
|
|
79
|
+
setError(err);
|
|
80
|
+
onErrorCb?.(err);
|
|
81
|
+
},
|
|
77
82
|
});
|
|
78
83
|
clientRef.current = client;
|
|
79
84
|
setError(null);
|
|
80
85
|
setTranscripts([]);
|
|
81
86
|
await client.connect();
|
|
82
|
-
}, [baseUrl, publishableKey, agentId, voiceId]);
|
|
87
|
+
}, [baseUrl, publishableKey, agentId, voiceId, onStatusChangeCb, onErrorCb, onTranscriptCb]);
|
|
83
88
|
const stop = useCallback(() => {
|
|
84
89
|
clientRef.current?.disconnect();
|
|
85
90
|
clientRef.current = null;
|
|
@@ -91,10 +96,19 @@ export function useFormmyVoice({ agentId, voiceId }) {
|
|
|
91
96
|
return next;
|
|
92
97
|
});
|
|
93
98
|
}, []);
|
|
99
|
+
const setMuted = useCallback((muted) => {
|
|
100
|
+
setIsMuted(muted);
|
|
101
|
+
clientRef.current?.setMuted(muted);
|
|
102
|
+
}, []);
|
|
103
|
+
const clearTranscripts = useCallback(() => {
|
|
104
|
+
setTranscripts([]);
|
|
105
|
+
}, []);
|
|
94
106
|
return {
|
|
95
107
|
start,
|
|
96
108
|
stop,
|
|
97
109
|
toggleMute,
|
|
110
|
+
setMuted,
|
|
111
|
+
clearTranscripts,
|
|
98
112
|
status,
|
|
99
113
|
isMuted,
|
|
100
114
|
isSpeaking: status === "speaking",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-formmy-voice.js","sourceRoot":"","sources":["../../src/hooks/use-formmy-voice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAA0C,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-formmy-voice.js","sourceRoot":"","sources":["../../src/hooks/use-formmy-voice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAA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