@umituz/react-native-ai-generation-content 1.17.40 → 1.17.41
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/package.json +1 -1
- package/src/features/script-generator/domain/constants/index.ts +10 -0
- package/src/features/script-generator/index.ts +3 -0
- package/src/features/script-generator/infrastructure/services/ScriptGenerationService.ts +62 -0
- package/src/features/script-generator/presentation/hooks/index.ts +1 -0
- package/src/features/script-generator/presentation/hooks/useScriptGenerator.ts +74 -0
package/package.json
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { VideoTypeOption } from "../presentation/components/VideoTypeSelector";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_VIDEO_TYPES: readonly VideoTypeOption[] = [
|
|
4
|
+
{ id: "product", name: "Product Demo", emoji: "📦" },
|
|
5
|
+
{ id: "tutorial", name: "Tutorial", emoji: "🎓" },
|
|
6
|
+
{ id: "promo", name: "Promo/Ad", emoji: "📣" },
|
|
7
|
+
{ id: "story", name: "Storytelling", emoji: "📖" },
|
|
8
|
+
{ id: "explainer", name: "Explainer", emoji: "💡" },
|
|
9
|
+
{ id: "vlog", name: "Vlog", emoji: "🎥" },
|
|
10
|
+
];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ScriptSection,
|
|
3
|
+
ScriptGenerationRequest,
|
|
4
|
+
} from "../domain/types/script.types";
|
|
5
|
+
import { DEFAULT_VIDEO_TYPES } from "../domain/constants";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ScriptGenerationService
|
|
9
|
+
* Handles building prompts and (eventually) calling AI providers for script generation.
|
|
10
|
+
*/
|
|
11
|
+
export class ScriptGenerationService {
|
|
12
|
+
/**
|
|
13
|
+
* Build prompt for script generation
|
|
14
|
+
*/
|
|
15
|
+
buildScriptPrompt(request: ScriptGenerationRequest): string {
|
|
16
|
+
const typeInfo = DEFAULT_VIDEO_TYPES.find((t) => t.id === request.videoType);
|
|
17
|
+
|
|
18
|
+
return `Generate a video script for a ${request.duration}-second ${typeInfo?.name || "video"} about: ${request.topic}
|
|
19
|
+
|
|
20
|
+
${request.targetAudience ? `Target Audience: ${request.targetAudience}` : ""}
|
|
21
|
+
${request.keyPoints ? `Key Points to Cover: ${request.keyPoints}` : ""}
|
|
22
|
+
|
|
23
|
+
Please create a detailed script with the following structure:
|
|
24
|
+
1. Hook (3-5 seconds): Attention-grabbing opening
|
|
25
|
+
2. Introduction (5-10 seconds): Brief intro to the topic
|
|
26
|
+
3. Main Content (${request.duration - 15} seconds): Core message and value
|
|
27
|
+
4. Call-to-Action (5 seconds): Clear next step for viewers
|
|
28
|
+
|
|
29
|
+
For each section, provide:
|
|
30
|
+
- Section title
|
|
31
|
+
- Voiceover text
|
|
32
|
+
- Duration in seconds
|
|
33
|
+
- Visual/scene suggestions
|
|
34
|
+
|
|
35
|
+
Format as JSON with this structure:
|
|
36
|
+
{
|
|
37
|
+
"sections": [
|
|
38
|
+
{
|
|
39
|
+
"type": "hook|intro|main|cta",
|
|
40
|
+
"title": "Section title",
|
|
41
|
+
"content": "Voiceover text",
|
|
42
|
+
"duration": 5,
|
|
43
|
+
"notes": "Visual suggestions"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"totalDuration": ${request.duration}
|
|
47
|
+
}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Generate script from request
|
|
52
|
+
*/
|
|
53
|
+
async generateScript(
|
|
54
|
+
request: ScriptGenerationRequest,
|
|
55
|
+
): Promise<readonly ScriptSection[] | null> {
|
|
56
|
+
// NOTE: This will be implemented by the app using a specific AI provider (like OpenAI or FAL)
|
|
57
|
+
// The package provides the structure and prompt building.
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const scriptGenerationService = new ScriptGenerationService();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useScriptGenerator";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import {
|
|
3
|
+
ScriptSection,
|
|
4
|
+
ScriptGenerationRequest,
|
|
5
|
+
} from "../../domain/types/script.types";
|
|
6
|
+
|
|
7
|
+
export interface UseScriptGeneratorProps {
|
|
8
|
+
readonly onGenerate: (request: ScriptGenerationRequest) => Promise<readonly ScriptSection[] | null>;
|
|
9
|
+
readonly onUseScript?: (script: readonly ScriptSection[]) => void;
|
|
10
|
+
readonly onAuthRequired?: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UseScriptGeneratorReturn {
|
|
14
|
+
readonly isGenerating: boolean;
|
|
15
|
+
readonly generatedScript: readonly ScriptSection[] | null;
|
|
16
|
+
readonly generateScript: (request: ScriptGenerationRequest) => Promise<void>;
|
|
17
|
+
readonly handleUseScript: () => void;
|
|
18
|
+
readonly resetState: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useScriptGenerator({
|
|
22
|
+
onGenerate,
|
|
23
|
+
onUseScript,
|
|
24
|
+
onAuthRequired,
|
|
25
|
+
}: UseScriptGeneratorProps): UseScriptGeneratorReturn {
|
|
26
|
+
const [isGenerating, setIsGenerating] = useState(false);
|
|
27
|
+
const [generatedScript, setGeneratedScript] = useState<readonly ScriptSection[] | null>(null);
|
|
28
|
+
|
|
29
|
+
const generateScript = useCallback(
|
|
30
|
+
async (request: ScriptGenerationRequest) => {
|
|
31
|
+
if (!request.topic.trim()) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (onAuthRequired) {
|
|
36
|
+
onAuthRequired();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setIsGenerating(true);
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const script = await onGenerate(request);
|
|
43
|
+
|
|
44
|
+
if (script) {
|
|
45
|
+
setGeneratedScript(script);
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("Script generation error:", error);
|
|
49
|
+
} finally {
|
|
50
|
+
setIsGenerating(false);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
[onGenerate, onAuthRequired],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const handleUseScript = useCallback(() => {
|
|
57
|
+
if (generatedScript && onUseScript) {
|
|
58
|
+
onUseScript(generatedScript);
|
|
59
|
+
}
|
|
60
|
+
}, [generatedScript, onUseScript]);
|
|
61
|
+
|
|
62
|
+
const resetState = useCallback(() => {
|
|
63
|
+
setGeneratedScript(null);
|
|
64
|
+
setIsGenerating(false);
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
isGenerating,
|
|
69
|
+
generatedScript,
|
|
70
|
+
generateScript,
|
|
71
|
+
handleUseScript,
|
|
72
|
+
resetState,
|
|
73
|
+
};
|
|
74
|
+
}
|