chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
import { PROFILE_NATIVE_SKILLS_PATH } from '@/constants'
|
||||
|
||||
import { mergeMissingSettings } from '../settings-merge'
|
||||
|
||||
/**
|
||||
* Set up skills settings
|
||||
*/
|
||||
export default async function (skillFriendlyName, currentSkill) {
|
||||
const skillName = path.basename(currentSkill.path)
|
||||
const skillSrcPath = path.join(currentSkill.path, 'src')
|
||||
const settingsPath = path.join(
|
||||
PROFILE_NATIVE_SKILLS_PATH,
|
||||
skillName,
|
||||
'settings.json'
|
||||
)
|
||||
const settingsSamplePath = path.join(skillSrcPath, 'settings.sample.json')
|
||||
|
||||
// If there is a bridge set from the skill settings
|
||||
if (currentSkill.bridge) {
|
||||
// Check if the settings and settings.sample file exist
|
||||
if (fs.existsSync(settingsPath) && fs.existsSync(settingsSamplePath)) {
|
||||
const settings = JSON.parse(
|
||||
await fs.promises.readFile(settingsPath, 'utf8')
|
||||
)
|
||||
const settingsSample = JSON.parse(
|
||||
await fs.promises.readFile(settingsSamplePath, 'utf8')
|
||||
)
|
||||
const mergedSettings = mergeMissingSettings(settingsSample, settings)
|
||||
|
||||
if (JSON.stringify(settings) !== JSON.stringify(mergedSettings)) {
|
||||
await fs.promises.mkdir(path.dirname(settingsPath), { recursive: true })
|
||||
await fs.promises.writeFile(
|
||||
settingsPath,
|
||||
`${JSON.stringify(mergedSettings, null, 2)}\n`
|
||||
)
|
||||
}
|
||||
} else if (!fs.existsSync(settingsSamplePath)) {
|
||||
// Stop the setup if the settings.sample.json of the current skill does not exist
|
||||
throw new Error(
|
||||
`The "${skillFriendlyName}" skill settings file does not exist. Try to pull the project (git pull)`
|
||||
)
|
||||
} else {
|
||||
// Duplicate settings.sample.json of the current skill to settings.json
|
||||
await fs.promises.mkdir(path.dirname(settingsPath), { recursive: true })
|
||||
await fs.promises.copyFile(settingsSamplePath, settingsPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import path from 'node:path'
|
||||
|
||||
import { SkillDomainHelper } from '@/helpers/skill-domain-helper'
|
||||
|
||||
import { createSetupStatus } from '../setup-status'
|
||||
|
||||
import setupSkillsSettings from './setup-skills-settings'
|
||||
import syncSkillDependencies from './sync-skill-dependencies'
|
||||
|
||||
/**
|
||||
* Browse skills and set them up
|
||||
*/
|
||||
export default async function () {
|
||||
const status = createSetupStatus('Setting up skills...').start()
|
||||
|
||||
try {
|
||||
const skillNames = SkillDomainHelper.listAllSkillFoldersSync()
|
||||
|
||||
for (const skillName of skillNames) {
|
||||
const currentSkill = await SkillDomainHelper.getNewSkillConfig(
|
||||
skillName,
|
||||
{ includeDisabled: true }
|
||||
)
|
||||
const currentSkillPath = SkillDomainHelper.getNewSkillConfigPath(
|
||||
skillName,
|
||||
{ includeDisabled: true }
|
||||
)
|
||||
|
||||
if (!currentSkill || !currentSkillPath) {
|
||||
continue
|
||||
}
|
||||
|
||||
const skillContext = {
|
||||
path: currentSkillPath ? path.dirname(currentSkillPath) : '',
|
||||
bridge: currentSkill.bridge
|
||||
}
|
||||
|
||||
await setupSkillsSettings(skillName, skillContext)
|
||||
await syncSkillDependencies(skillName, skillContext)
|
||||
}
|
||||
|
||||
status.succeed('Skills: ready')
|
||||
} catch (e) {
|
||||
status.fail('Failed to set up skills')
|
||||
throw e
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import path from 'node:path'
|
||||
|
||||
import {
|
||||
syncNodejsSourceDependencies,
|
||||
syncPythonSourceDependencies
|
||||
} from '../sync-source-dependencies'
|
||||
|
||||
/**
|
||||
* Sync skill dependencies only when a skill is installed, updated, or its
|
||||
* dependency manifest changes.
|
||||
*/
|
||||
export default async function syncSkillDependencies(
|
||||
_skillFriendlyName,
|
||||
currentSkill
|
||||
) {
|
||||
const skillSRCPath = path.join(currentSkill.path, 'src')
|
||||
|
||||
if (currentSkill.bridge === 'nodejs') {
|
||||
await syncNodejsSourceDependencies(skillSRCPath)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (currentSkill.bridge === 'python') {
|
||||
await syncPythonSourceDependencies(skillSRCPath)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user