1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-08-17 06:00:33 +03:00

chore: rename config.json to settings.json

This commit is contained in:
Divlo 2023-05-26 23:31:25 +02:00
parent 30e405bbe3
commit 4f5b385fd7
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9
29 changed files with 91 additions and 165 deletions

4
.gitignore vendored
View File

@ -29,9 +29,7 @@ tcp_server/src/Pipfile.lock
!bridges/python/**/.gitkeep
!bridges/nodejs/**/.gitkeep
!**/*.sample*
packages/**/config/config.json
skills/**/src/config.json
packages/**/data/db/*.json
skills/**/src/settings.json
skills/**/memory/*.json
skills/**/memory/*.db*
core/data/models/*.nlp

View File

@ -1,79 +0,0 @@
import fs from 'node:fs'
import path from 'node:path'
import { commandSync } from 'execa'
import { LogHelper } from '@/helpers/log-helper'
/**
* Set up skills configuration
*/
export default async function (skillFriendlyName, currentSkill) {
const configDir = path.join(currentSkill.path, 'src')
const configFile = path.join(configDir, 'config.json')
const configSampleFile = path.join(configDir, 'config.sample.json')
// If there is a bridge set from the skill config
if (currentSkill.bridge) {
// Check if the config and config.sample file exist
if (fs.existsSync(configFile) && fs.existsSync(configSampleFile)) {
const config = JSON.parse(
await fs.promises.readFile(configFile, 'utf8')
)?.configurations
const configSample = JSON.parse(
await fs.promises.readFile(configSampleFile, 'utf8')
)?.configurations
const configKeys = Object.keys(config)
const configSampleKeys = Object.keys(configSample)
// Check if there is a new config key in the config sample compared to the config.json
if (JSON.stringify(configKeys) !== JSON.stringify(configSampleKeys)) {
// Browse config keys of the new skill config
for (let j = 0; j < configSampleKeys.length; j += 1) {
// Check if the current config key does not exist
if (configKeys.includes(configSampleKeys[j]) === false) {
LogHelper.info(
`Adding new configuration key "${configSampleKeys[j]}" for the ${skillFriendlyName} skill...`
)
// Prepare to inject the new config key object
const configKey = {
[configSampleKeys[j]]: configSample[configSampleKeys[j]]
}
try {
// Add new skill configuration in the config.json file
commandSync(
`json -I -f ${configFile} -e 'this.configurations.${
configSampleKeys[j]
}=${JSON.stringify(configKey[configSampleKeys[j]])}'`,
{ shell: true }
)
LogHelper.success(
`"${configSampleKeys[j]}" configuration key added to ${configFile}`
)
} catch (e) {
LogHelper.error(
`Error while adding "${configSampleKeys[j]}" configuration key to ${configFile}: ${e}`
)
}
}
}
}
} else if (!fs.existsSync(configSampleFile)) {
// Stop the setup if the config.sample.json of the current skill does not exist
LogHelper.error(
`The "${skillFriendlyName}" skill configuration file does not exist. Try to pull the project (git pull)`
)
} else {
// Duplicate config.sample.json of the current skill to config.json
fs.createReadStream(configSampleFile).pipe(
fs.createWriteStream(`${configDir}/config.json`)
)
LogHelper.success(
`"${skillFriendlyName}" skill configuration file created`
)
}
}
}

View File

@ -0,0 +1,77 @@
import fs from 'node:fs'
import path from 'node:path'
import { commandSync } from 'execa'
import { LogHelper } from '@/helpers/log-helper'
/**
* Set up skills settings
*/
export default async function (skillFriendlyName, currentSkill) {
const skillSrcPath = path.join(currentSkill.path, 'src')
const settingsPath = path.join(skillSrcPath, '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 settingsKeys = Object.keys(settings)
const settingsSampleKeys = Object.keys(settingsSample)
// Check if there is a new settings key in the settings sample compared to the settings.json
if (JSON.stringify(settingsKeys) !== JSON.stringify(settingsSampleKeys)) {
// Browse settings keys of the new settings config
for (let j = 0; j < settingsSampleKeys.length; j += 1) {
// Check if the current settings key does not exist
if (!settingsKeys.includes(settingsSampleKeys[j])) {
LogHelper.info(
`Adding new settings key "${settingsSampleKeys[j]}" for the ${skillFriendlyName} skill...`
)
// Prepare to inject the new settings key object
const configKey = {
[settingsSampleKeys[j]]: settingsSample[settingsSampleKeys[j]]
}
try {
// Add new skill settings in the settings.json file
commandSync(
`json -I -f ${settingsPath} -e 'this.${settingsSampleKeys[j]}=${JSON.stringify(configKey[settingsSampleKeys[j]])}'`,
{ shell: true }
)
LogHelper.success(
`"${settingsSampleKeys[j]}" settings key added to ${settingsPath}`
)
} catch (e) {
LogHelper.error(
`Error while adding "${settingsSampleKeys[j]}" settings key to ${settingsPath}: ${e}`
)
}
}
}
}
} else if (!fs.existsSync(settingsSamplePath)) {
// Stop the setup if the settings.sample.json of the current skill does not exist
LogHelper.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
fs.createReadStream(settingsSamplePath).pipe(
fs.createWriteStream(`${skillSrcPath}/settings.json`)
)
LogHelper.success(
`"${skillFriendlyName}" skill settings file created`
)
}
}
}

View File

@ -1,7 +1,7 @@
import { LogHelper } from '@/helpers/log-helper'
import { SkillDomainHelper } from '@/helpers/skill-domain-helper'
import setupSkillsConfig from './setup-skills-config'
import setupSkillsSettings from './setup-skills-settings'
import installNodejsSkillsPackages from './install-nodejs-skills-packages'
/**
@ -23,7 +23,7 @@ export default async function () {
LogHelper.info(`Setting up "${skillFriendlyName}" skill...`)
await setupSkillsConfig(skillFriendlyName, currentSkill)
await setupSkillsSettings(skillFriendlyName, currentSkill)
await installNodejsSkillsPackages(skillFriendlyName, currentSkill)
LogHelper.success(`"${skillFriendlyName}" skill set up`)

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +0,0 @@
{
"configurations": {
"options": {},
"credentials": {}
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -1,15 +0,0 @@
{
"configurations": {
"options": {
"playlist_id": "PLAYLIST_ID",
"synchronization": {
"enabled": true,
"method": "direct",
"email": ""
}
},
"credentials": {
"api_key": "YOUR_GOOGLE_API_KEY"
}
}
}