1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-23 20:12:08 +03:00

feat(bridge/nodejs): first draft

This commit is contained in:
louistiti 2023-05-02 23:53:41 +08:00
parent 2e3796642d
commit 9b839d3e66
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669
12 changed files with 117 additions and 24 deletions

View File

@ -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)
}
}
})()

View File

@ -1,23 +1,10 @@
{
"extends": "@tsconfig/node16-strictest/tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist/bin",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"ignoreDeprecations": "5.0",
"allowJs": true,
"checkJs": false,
"resolveJsonModule": true
"baseUrl": "."
},
"ts-node": {
"swc": true,
"require": ["tsconfig-paths/register"],
"files": true
},
"files": [],
"include": ["src/**/*"],
"exclude": ["dist"]
"exclude": ["node_modules", "dist"]
}

View File

@ -141,6 +141,11 @@
"route": "/api/action/games/rochambeau/rematch",
"params": []
},
{
"method": "GET",
"route": "/api/action/leon/age/run",
"params": []
},
{
"method": "GET",
"route": "/api/action/leon/color/favorite_color",

View File

@ -72,11 +72,13 @@ export const PYTHON_BRIDGE_BIN_PATH = path.join(
BINARIES_FOLDER_NAME,
PYTHON_BRIDGE_BIN_NAME
)
export const NODEJS_BRIDGE_BIN_PATH = `${process.execPath} ${path.join(
NODEJS_BRIDGE_DIST_PATH,
'bin',
NODEJS_BRIDGE_BIN_NAME
)}`
export const NODEJS_BRIDGE_BIN_PATH = `${path.join(
process.cwd(),
'node_modules',
'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']

View File

View 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..."]
}
}

View File

View 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"
}
}

View File

@ -0,0 +1,3 @@
export function run(): string {
return 'hello'
}

View File

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

View File

View File