MCPcopy
hub / github.com/stackblitz/bolt.new / usePromptEnhancer

Function usePromptEnhancer

app/lib/hooks/usePromptEnhancer.ts:6–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4const logger = createScopedLogger('usePromptEnhancement');
5
6export function usePromptEnhancer() {
7 const [enhancingPrompt, setEnhancingPrompt] = useState(false);
8 const [promptEnhanced, setPromptEnhanced] = useState(false);
9
10 const resetEnhancer = () => {
11 setEnhancingPrompt(false);
12 setPromptEnhanced(false);
13 };
14
15 const enhancePrompt = async (input: string, setInput: (value: string) => void) => {
16 setEnhancingPrompt(true);
17 setPromptEnhanced(false);
18
19 const response = await fetch('/api/enhancer', {
20 method: 'POST',
21 body: JSON.stringify({
22 message: input,
23 }),
24 });
25
26 const reader = response.body?.getReader();
27
28 const originalInput = input;
29
30 if (reader) {
31 const decoder = new TextDecoder();
32
33 let _input = '';
34 let _error;
35
36 try {
37 setInput('');
38
39 while (true) {
40 const { value, done } = await reader.read();
41
42 if (done) {
43 break;
44 }
45
46 _input += decoder.decode(value);
47
48 logger.trace('Set input', _input);
49
50 setInput(_input);
51 }
52 } catch (error) {
53 _error = error;
54 setInput(originalInput);
55 } finally {
56 if (_error) {
57 logger.error(_error);
58 }
59
60 setEnhancingPrompt(false);
61 setPromptEnhanced(true);
62
63 setTimeout(() => {

Callers 1

Chat.client.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected