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

feat(server): create updater

This commit is contained in:
Louis Grenard 2024-02-14 17:37:21 +08:00
parent dba5d90b94
commit 30c9d3bce5
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669
6 changed files with 73 additions and 14 deletions

View File

@ -1,5 +1,16 @@
{
"endpoints": [
{
"method": "POST",
"route": "/api/action/news/github_trends/run",
"params": ["number", "daterange"],
"entitiesType": "builtIn"
},
{
"method": "GET",
"route": "/api/action/news/product_hunt_trends/run",
"params": []
},
{
"method": "POST",
"route": "/api/action/games/akinator/choose_thematic",
@ -52,17 +63,6 @@
"route": "/api/action/games/rochambeau/rematch",
"params": []
},
{
"method": "POST",
"route": "/api/action/news/github_trends/run",
"params": ["number", "daterange"],
"entitiesType": "builtIn"
},
{
"method": "GET",
"route": "/api/action/news/product_hunt_trends/run",
"params": []
},
{
"method": "POST",
"route": "/api/action/productivity/todo_list/create_list",

View File

@ -69,8 +69,6 @@ export default class ModelLoader {
)
)
} else {
LogHelper.title('Model Loader')
try {
const container = await containerBootstrap()
@ -82,6 +80,7 @@ export default class ModelLoader {
nluManager.settings.spellCheck = true
await this.globalResolversNLPContainer.load(modelPath)
LogHelper.title('Model Loader')
LogHelper.success('Global resolvers NLP model loaded')
resolve()

View File

@ -47,7 +47,7 @@ export default class TCPClient {
this.tcpSocket.on('connect', () => {
LogHelper.title(`${this.name} TCP Client`)
LogHelper.success(
`Connected to the ${this.name} TCP server tcp://${this.host}:${this.port}`
`Connected to the ${this.name} TCP server at tcp://${this.host}:${this.port}`
)
this.reconnectCounter = 0

View File

@ -3,6 +3,7 @@ import fs from 'node:fs'
import {
IS_DEVELOPMENT_ENV,
IS_PRODUCTION_ENV,
IS_TELEMETRY_ENABLED,
LANG as LEON_LANG,
PYTHON_TCP_SERVER_BIN_PATH
@ -14,6 +15,7 @@ import {
LLM_TCP_CLIENT,
LLM_TCP_SERVER
} from '@/core'
import { Updater } from '@/updater'
import { Telemetry } from '@/telemetry'
import { LangHelper } from '@/helpers/lang-helper'
import { LogHelper } from '@/helpers/log-helper'
@ -56,6 +58,17 @@ import { LogHelper } from '@/helpers/log-helper'
// Start the socket server
SOCKET_SERVER.init()
// Check for updates on startup and every 24 hours
if (IS_PRODUCTION_ENV) {
Updater.checkForUpdates()
setInterval(
() => {
Updater.checkForUpdates()
},
1_000 * 3_600 * 24
)
}
// Telemetry events
if (IS_TELEMETRY_ENABLED) {
Telemetry.start()

View File

@ -109,6 +109,11 @@ const GLOBAL_DATA_SCHEMAS = {
)
}
/**
* New updates checking
*/
LogHelper.info('Checking for new updates...')
/**
* Voice configuration checking
*/

42
server/src/updater.ts Normal file
View File

@ -0,0 +1,42 @@
import axios from 'axios'
import { LEON_VERSION } from '@/constants'
import { LogHelper } from '@/helpers/log-helper'
export class Updater {
private static readonly currentVersion = LEON_VERSION
private static readonly isDevelopment = (LEON_VERSION || '').includes('+dev')
private static readonly gitBranch = this.isDevelopment ? 'develop' : 'master'
private static readonly axios = axios.create({
baseURL: 'https://raw.githubusercontent.com/leon-ai/leon',
timeout: 7_000
})
public static async checkForUpdates(): Promise<void> {
LogHelper.title('Updater')
LogHelper.info('Checking for updates...')
try {
const { data } = await this.axios.get(`/${this.gitBranch}/package.json`)
const latestVersion = data.version
LogHelper.title('Updater')
if (latestVersion !== this.currentVersion) {
LogHelper.warning(`A new version is available: ${latestVersion}`)
LogHelper.warning(`Current version: ${this.currentVersion}`)
LogHelper.warning(
`Run the following command to update Leon and benefit from the latest features: "npm install --save @leon-ai/leon@${latestVersion}"`
)
} else {
const releaseMode = this.isDevelopment ? 'development' : 'stable'
LogHelper.success(
`You are using the latest ${releaseMode} version of Leon`
)
}
} catch (e) {
LogHelper.warning(`Failed to check for updates: ${e}`)
}
}
}