MCPcopy
hub / github.com/srcbookdev/srcbook / generate

Function generate

packages/web/src/components/generate-srcbook-modal.tsx:46–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 );
45
46 const generate = async () => {
47 if (!query) {
48 return;
49 }
50
51 setError(null);
52 setStatus('loading');
53
54 // Some errors will be handled by the API handler and return with
55 // {error: true, result: {message: string}}}
56 // Some example errors that we expect are:
57 // - the generated text from the LLM did not parse correctly into Srcbook format
58 // - the API key is invalid
59 // - rate limits or out-of-credits issues
60 const { result, error } = await generateSrcbook({ query });
61
62 if (error) {
63 console.error(result);
64 setStatus('idle');
65 if (/Incorrect API key provided/.test(result)) {
66 setError('api_key');
67 } else {
68 setError('generic');
69 }
70 } else {
71 openSrcbook(result.dir);
72 }
73 };
74
75 return (
76 <Dialog open={open} onOpenChange={setOpen}>

Callers 1

GenerateSrcbookModalFunction · 0.70

Calls 3

generateSrcbookFunction · 0.90
openSrcbookFunction · 0.70
setErrorFunction · 0.50

Tested by

no test coverage detected