返回 AiToEarn
skill-init.service.ts
根目录 / project / aitoearn-backend / apps / aitoearn-ai / src / core / agent / skill-init.service.ts
1 import * as fs from 'node:fs'
2 import * as path from 'node:path'
3 import { Injectable, Logger, OnModuleInit } from '@nestjs/common'
4
5 const SKILL_DIRECTORIES = [
6 'generating-images',
7 'generating-videos',
8 'editing-videos',
9 'editing-images',
10 'transferring-video-styles',
11 'generating-drama-recaps',
12 'composing-videos',
13 'translating-videos',
14 'removing-subtitles',
15 'analyzing-videos',
16 'managing-content',
17 'crawling-social-media',
18 'extracting-thumbnails',
19 ] as const
20
21 @Injectable()
22 export class SkillInitService implements OnModuleInit {
23 private readonly logger = new Logger(SkillInitService.name)
24 private readonly sourceDir = path.join(__dirname, 'skills')
25 private readonly targetDir = path.join(process.cwd(), '.claude-session', '.claude', 'skills')
26
27 async onModuleInit(): Promise<void> {
28 try {
29 this.initializeSkills()
30 this.logger.log(`Skills initialized: ${this.targetDir}`)
31 }
32 catch (error) {
33 this.logger.error('Failed to initialize skills', error)
34 }
35 }
36
37 private initializeSkills(): void {
38 fs.mkdirSync(this.targetDir, { recursive: true })
39
40 for (const skillName of SKILL_DIRECTORIES) {
41 this.copySkillDirectory(skillName)
42 }
43 }
44
45 private copySkillDirectory(skillName: string): void {
46 const src = path.join(this.sourceDir, skillName)
47 const dest = path.join(this.targetDir, skillName)
48
49 if (!fs.existsSync(src)) {
50 this.logger.warn(`Skill not found: ${skillName}`)
51 return
52 }
53
54 fs.mkdirSync(dest, { recursive: true })
55
56 for (const file of fs.readdirSync(src)) {
57 const srcFile = path.join(src, file)
58 if (fs.statSync(srcFile).isFile()) {
59 fs.copyFileSync(srcFile, path.join(dest, file))
60 }
61 }
62 }
63 }
64
64 lines TYPESCRIPT