mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-27 08:06:03 +03:00
feat(bridge/nodejs): first draft
This commit is contained in:
parent
2e3796642d
commit
9b839d3e66
@ -1,5 +1,71 @@
|
|||||||
import { VERSION } from './version'
|
import fs from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
console.log('[WIP] Node.js bridge', VERSION)
|
const {
|
||||||
|
argv: [, , INTENT_OBJ_FILE_PATH]
|
||||||
|
} = process
|
||||||
|
|
||||||
// TODO
|
;(async (): Promise<void> => {
|
||||||
|
if (INTENT_OBJ_FILE_PATH) {
|
||||||
|
const {
|
||||||
|
domain,
|
||||||
|
skill,
|
||||||
|
action,
|
||||||
|
lang,
|
||||||
|
utterance,
|
||||||
|
current_entities: currentEntities,
|
||||||
|
entities,
|
||||||
|
current_resolvers: currentResolvers,
|
||||||
|
resolvers,
|
||||||
|
slots
|
||||||
|
} = JSON.parse(await fs.promises.readFile(INTENT_OBJ_FILE_PATH, 'utf8'))
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
lang,
|
||||||
|
utterance,
|
||||||
|
currentEntities,
|
||||||
|
entities,
|
||||||
|
currentResolvers,
|
||||||
|
resolvers,
|
||||||
|
slots
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { [action]: actionFunction } = await import(
|
||||||
|
path.join(
|
||||||
|
process.cwd(),
|
||||||
|
'skills',
|
||||||
|
domain,
|
||||||
|
skill,
|
||||||
|
'src',
|
||||||
|
'actions',
|
||||||
|
`${action}.ts`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const speech = actionFunction(params)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
JSON.stringify({
|
||||||
|
domain,
|
||||||
|
skill,
|
||||||
|
action,
|
||||||
|
lang,
|
||||||
|
utterance,
|
||||||
|
entities,
|
||||||
|
slots,
|
||||||
|
// TODO
|
||||||
|
output: {
|
||||||
|
type: 'end',
|
||||||
|
codes: '',
|
||||||
|
speech,
|
||||||
|
core: {},
|
||||||
|
options: {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error while running action:', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
@ -1,23 +1,10 @@
|
|||||||
{
|
{
|
||||||
"extends": "@tsconfig/node16-strictest/tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"outDir": "./dist/bin",
|
"outDir": "./dist/bin",
|
||||||
"baseUrl": ".",
|
"baseUrl": "."
|
||||||
"paths": {
|
|
||||||
"@/*": ["./src/*"]
|
|
||||||
},
|
|
||||||
"ignoreDeprecations": "5.0",
|
|
||||||
"allowJs": true,
|
|
||||||
"checkJs": false,
|
|
||||||
"resolveJsonModule": true
|
|
||||||
},
|
},
|
||||||
"ts-node": {
|
|
||||||
"swc": true,
|
|
||||||
"require": ["tsconfig-paths/register"],
|
|
||||||
"files": true
|
|
||||||
},
|
|
||||||
"files": [],
|
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*"],
|
||||||
"exclude": ["dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,11 @@
|
|||||||
"route": "/api/action/games/rochambeau/rematch",
|
"route": "/api/action/games/rochambeau/rematch",
|
||||||
"params": []
|
"params": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"route": "/api/action/leon/age/run",
|
||||||
|
"params": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"route": "/api/action/leon/color/favorite_color",
|
"route": "/api/action/leon/color/favorite_color",
|
||||||
|
@ -72,11 +72,13 @@ export const PYTHON_BRIDGE_BIN_PATH = path.join(
|
|||||||
BINARIES_FOLDER_NAME,
|
BINARIES_FOLDER_NAME,
|
||||||
PYTHON_BRIDGE_BIN_NAME
|
PYTHON_BRIDGE_BIN_NAME
|
||||||
)
|
)
|
||||||
export const NODEJS_BRIDGE_BIN_PATH = `${process.execPath} ${path.join(
|
export const NODEJS_BRIDGE_BIN_PATH = `${path.join(
|
||||||
NODEJS_BRIDGE_DIST_PATH,
|
process.cwd(),
|
||||||
'bin',
|
'node_modules',
|
||||||
NODEJS_BRIDGE_BIN_NAME
|
'ts-node',
|
||||||
)}`
|
'dist',
|
||||||
|
'bin.js'
|
||||||
|
)} --swc ${path.join(NODEJS_BRIDGE_DIST_PATH, 'bin', NODEJS_BRIDGE_BIN_NAME)}`
|
||||||
|
|
||||||
export const LEON_VERSION = process.env['npm_package_version']
|
export const LEON_VERSION = process.env['npm_package_version']
|
||||||
|
|
||||||
|
0
skills/leon/age/README.md
Normal file
0
skills/leon/age/README.md
Normal file
12
skills/leon/age/config/en.json
Normal file
12
skills/leon/age/config/en.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$schema": "../../../../schemas/skill-schemas/skill-config.json",
|
||||||
|
"actions": {
|
||||||
|
"run": {
|
||||||
|
"type": "logic",
|
||||||
|
"utterance_samples": ["How old are you?"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"answers": {
|
||||||
|
"default": ["I'm..."]
|
||||||
|
}
|
||||||
|
}
|
0
skills/leon/age/memory/.gitkeep
Normal file
0
skills/leon/age/memory/.gitkeep
Normal file
12
skills/leon/age/skill.json
Normal file
12
skills/leon/age/skill.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$schema": "../../../schemas/skill-schemas/skill.json",
|
||||||
|
"name": "Age",
|
||||||
|
"bridge": "nodejs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Leon tells his age.",
|
||||||
|
"author": {
|
||||||
|
"name": "Louis Grenard",
|
||||||
|
"email": "louis@getleon.ai",
|
||||||
|
"url": "https://github.com/louistiti"
|
||||||
|
}
|
||||||
|
}
|
3
skills/leon/age/src/actions/run.ts
Normal file
3
skills/leon/age/src/actions/run.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export function run(): string {
|
||||||
|
return 'hello'
|
||||||
|
}
|
6
skills/leon/age/src/config.sample.json
Normal file
6
skills/leon/age/src/config.sample.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"configurations": {
|
||||||
|
"options": {},
|
||||||
|
"credentials": {}
|
||||||
|
}
|
||||||
|
}
|
0
skills/leon/age/src/lib/.gitkeep
Normal file
0
skills/leon/age/src/lib/.gitkeep
Normal file
0
skills/leon/age/test/.gitkeep
Normal file
0
skills/leon/age/test/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user