mirror of
https://github.com/leon-ai/leon.git
synced 2024-09-11 18:27:21 +03:00
feat: kick off telemetry client
This commit is contained in:
parent
19c569b76a
commit
337854ab02
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@ package-lock.json
|
||||
npm-debug.log
|
||||
debug.log
|
||||
.env
|
||||
leon.json
|
||||
bridges/python/src/Pipfile.lock
|
||||
tcp_server/src/Pipfile.lock
|
||||
!tcp_server/**/.gitkeep
|
||||
|
29
scripts/setup/create-instance-id.js
Normal file
29
scripts/setup/create-instance-id.js
Normal file
@ -0,0 +1,29 @@
|
||||
import fs from 'node:fs'
|
||||
|
||||
import { LEON_FILE_PATH } from '@/constants'
|
||||
import { Telemetry } from '@/telemetry'
|
||||
|
||||
// TODO: export default
|
||||
;(async () => {
|
||||
try {
|
||||
const { instanceID, birthDate } = await Telemetry.postinstall()
|
||||
|
||||
if (!fs.existsSync(LEON_FILE_PATH)) {
|
||||
await fs.promises.writeFile(
|
||||
LEON_FILE_PATH,
|
||||
JSON.stringify(
|
||||
{
|
||||
instanceID,
|
||||
birthDate
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// resolve()
|
||||
} catch (e) {
|
||||
// reject(new Error(`Failed to create instance ID: ${e}`))
|
||||
}
|
||||
})()
|
@ -9,6 +9,7 @@ import setupDotenv from './setup-dotenv'
|
||||
import setupCore from './setup-core'
|
||||
import setupSkillsConfig from './setup-skills-config'
|
||||
import setupPythonBinaries from './setup-python-binaries'
|
||||
// import createInstanceID from './create-instance-id'
|
||||
|
||||
// Do not load ".env" file because it is not created yet
|
||||
|
||||
@ -26,6 +27,7 @@ import setupPythonBinaries from './setup-python-binaries'
|
||||
await generateJsonSchemas()
|
||||
LoaderHelper.start()
|
||||
await train()
|
||||
// await createInstanceID()
|
||||
|
||||
LogHelper.default('')
|
||||
LogHelper.success('Hooray! Leon is installed and ready to go!')
|
||||
|
@ -108,3 +108,11 @@ export const SERVER_PATH = path.join(
|
||||
IS_PRODUCTION_ENV ? 'dist' : 'src'
|
||||
)
|
||||
export const TMP_PATH = path.join(SERVER_PATH, 'tmp')
|
||||
export const LEON_FILE_PATH = path.join('leon.json')
|
||||
|
||||
/**
|
||||
* Misc
|
||||
*/
|
||||
export const INSTANCE_ID = fs.existsSync(LEON_FILE_PATH)
|
||||
? JSON.parse(fs.readFileSync(LEON_FILE_PATH, 'utf8')).instanceID
|
||||
: null
|
||||
|
@ -1,7 +1,27 @@
|
||||
import axios from 'axios'
|
||||
|
||||
import { INSTANCE_ID } from '@/constants'
|
||||
|
||||
const IS_TELEMETRY_ENABLED = process.env['LEON_TELEMETRY'] === 'true'
|
||||
const INSTANCE_ID = '' // TODO: read from file (leon.json > instanceID)
|
||||
|
||||
interface PostintallResponse {
|
||||
instanceID: string
|
||||
birthDate: number
|
||||
}
|
||||
|
||||
export class Telemetry {
|
||||
// private static readonly serviceURL = 'https://telemetry.getleon.ai'
|
||||
private static readonly serviceURL = 'http://localhost:3000'
|
||||
private static readonly instanceID = INSTANCE_ID
|
||||
|
||||
public static async postinstall(): Promise<PostintallResponse> {
|
||||
const { data } = await axios.post(`${this.serviceURL}/on-postinstall`, {
|
||||
instanceID: this.instanceID
|
||||
})
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
public static send(): void {
|
||||
if (IS_TELEMETRY_ENABLED) {
|
||||
// TODO
|
||||
|
Loading…
Reference in New Issue
Block a user