mirror of
https://github.com/leon-ai/leon.git
synced 2024-12-18 14:21:32 +03:00
Merge branch 'skill-widget-ideas' into develop
This commit is contained in:
commit
46299ef4eb
@ -79,7 +79,15 @@ export default class Client {
|
|||||||
const root = createRoot(container)
|
const root = createRoot(container)
|
||||||
|
|
||||||
// TODO: widget: pass props and dynamic component loading according to type
|
// TODO: widget: pass props and dynamic component loading according to type
|
||||||
root.render(Button({ children: 'OK' }))
|
const widgets = {
|
||||||
|
Button: (options) => {
|
||||||
|
return Button({
|
||||||
|
children: options.text
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
root.render(widgets[data.type](data.options))
|
||||||
})
|
})
|
||||||
|
|
||||||
this.socket.on('audio-forwarded', (data, cb) => {
|
this.socket.on('audio-forwarded', (data, cb) => {
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
|
import { Widget } from '../widget'
|
||||||
|
|
||||||
// TODO: contains the button API. rendering engine <-> SDK
|
// TODO: contains the button API. rendering engine <-> SDK
|
||||||
interface Options {
|
interface ButtonOptions {
|
||||||
text: string
|
text: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Button {
|
export class Button extends Widget<ButtonOptions> {
|
||||||
private readonly text: string
|
public constructor(options: ButtonOptions) {
|
||||||
|
super(options)
|
||||||
constructor(options: Options) {
|
|
||||||
this.text = options.text
|
|
||||||
|
|
||||||
console.log('Button constructor', this.text)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ interface MemoryOptions<T> {
|
|||||||
defaultMemory?: T
|
defaultMemory?: T
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Memory<T> {
|
export class Memory<T = unknown> {
|
||||||
private readonly memoryPath: string | undefined
|
private readonly memoryPath: string | undefined
|
||||||
private readonly name: string
|
private readonly name: string
|
||||||
private readonly defaultMemory: T | undefined
|
private readonly defaultMemory: T | undefined
|
||||||
@ -55,12 +55,14 @@ export class Memory<T> {
|
|||||||
* Read the memory
|
* Read the memory
|
||||||
* @example read()
|
* @example read()
|
||||||
*/
|
*/
|
||||||
public async read(): Promise<T | undefined> {
|
public async read(): Promise<T> {
|
||||||
try {
|
|
||||||
if (!this.memoryPath) {
|
if (!this.memoryPath) {
|
||||||
return
|
throw new Error(
|
||||||
|
`You cannot read the memory "${this.name}" as it belongs to another skill which haven't written to this memory yet`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
if (!fs.existsSync(this.memoryPath)) {
|
if (!fs.existsSync(this.memoryPath)) {
|
||||||
await this.clear()
|
await this.clear()
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,10 @@
|
|||||||
*/
|
*/
|
||||||
import type { ActionParams, IntentObject } from '@/core/brain/types'
|
import type { ActionParams, IntentObject } from '@/core/brain/types'
|
||||||
|
|
||||||
import type { Button } from '@sdk/aurora/button'
|
|
||||||
|
|
||||||
export type { ActionParams, IntentObject }
|
export type { ActionParams, IntentObject }
|
||||||
|
|
||||||
export type ActionFunction = (params: ActionParams) => Promise<void>
|
export type ActionFunction = (params: ActionParams) => Promise<void>
|
||||||
|
|
||||||
/**
|
|
||||||
* Aurora
|
|
||||||
*/
|
|
||||||
export type AuroraComponent = Button // TODO
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Answer types
|
* Answer types
|
||||||
*/
|
*/
|
||||||
|
@ -1,23 +1,9 @@
|
|||||||
import type { AuroraComponent } from '@sdk/types'
|
export abstract class Widget<T> {
|
||||||
|
public readonly type: string
|
||||||
|
public readonly options: T
|
||||||
|
|
||||||
interface SerializedAuroraComponent {
|
protected constructor(options: T) {
|
||||||
type: string
|
this.type = this.constructor.name
|
||||||
props: Record<string, unknown>
|
this.options = options
|
||||||
}
|
|
||||||
|
|
||||||
export class Widget {
|
|
||||||
private readonly components: SerializedAuroraComponent[]
|
|
||||||
|
|
||||||
constructor(components: AuroraComponent[]) {
|
|
||||||
this.components = components.map((component) => {
|
|
||||||
return {
|
|
||||||
type: component.constructor.name,
|
|
||||||
props: {
|
|
||||||
...component
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log('Widget constructor', this.components)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,11 +159,11 @@ dotenv.config()
|
|||||||
if (Math.round(freeRAMInGB) < MINIMUM_REQUIRED_RAM) {
|
if (Math.round(freeRAMInGB) < MINIMUM_REQUIRED_RAM) {
|
||||||
report.can_run.v = false
|
report.can_run.v = false
|
||||||
LogHelper.error(
|
LogHelper.error(
|
||||||
`Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM`
|
`Free RAM: ${freeRAMInGB} GB | Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM`
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
LogHelper.success(
|
LogHelper.success(
|
||||||
`Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB`
|
`Free RAM: ${freeRAMInGB} GB | Total RAM: ${totalRAMInGB} GB`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,11 +101,11 @@ const GLOBAL_DATA_SCHEMAS = {
|
|||||||
|
|
||||||
if (freeRAMInGB < MINIMUM_REQUIRED_RAM) {
|
if (freeRAMInGB < MINIMUM_REQUIRED_RAM) {
|
||||||
LogHelper.warning(
|
LogHelper.warning(
|
||||||
`Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM. It may not work as expected.`
|
`Free RAM: ${freeRAMInGB} GB | Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM. It may not work as expected.`
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
LogHelper.success(
|
LogHelper.success(
|
||||||
`Minimum required RAM: ${MINIMUM_REQUIRED_RAM} GB | Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB`
|
`Minimum required RAM: ${MINIMUM_REQUIRED_RAM} GB | Free RAM: ${freeRAMInGB} GB | Total RAM: ${totalRAMInGB} GB`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ import utility from 'utility' // TODO
|
|||||||
|
|
||||||
import type { ActionFunction } from '@sdk/types'
|
import type { ActionFunction } from '@sdk/types'
|
||||||
import { leon } from '@sdk/leon'
|
import { leon } from '@sdk/leon'
|
||||||
import { Widget } from '@sdk/widget'
|
|
||||||
import { Network } from '@sdk/network'
|
import { Network } from '@sdk/network'
|
||||||
import { Button } from '@sdk/aurora/button'
|
import { Button } from '@sdk/aurora/button'
|
||||||
import { Memory } from '@sdk/memory'
|
import { Memory } from '@sdk/memory'
|
||||||
@ -21,20 +20,21 @@ export const run: ActionFunction = async function () {
|
|||||||
const button = new Button({
|
const button = new Button({
|
||||||
text: 'Hello world from action skill'
|
text: 'Hello world from action skill'
|
||||||
})
|
})
|
||||||
const widget = new Widget([button])
|
await leon.answer({ widget: button })
|
||||||
|
|
||||||
await leon.answer({ widget })
|
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
||||||
const otherSkillMemory = new Memory<unknown>({
|
const otherSkillMemory = new Memory({
|
||||||
name: 'productivity:todo_list:db'
|
name: 'productivity:todo_list:db'
|
||||||
})
|
})
|
||||||
const postsMemory = new Memory<Post[]>({ name: 'posts', defaultMemory: [] })
|
try {
|
||||||
const todoLists = await otherSkillMemory.read()
|
const todoLists = await otherSkillMemory.read()
|
||||||
|
|
||||||
console.log('todoLists', todoLists)
|
console.log('todoLists', todoLists)
|
||||||
|
} catch {
|
||||||
|
console.log('todoLists', [])
|
||||||
|
}
|
||||||
|
|
||||||
|
const postsMemory = new Memory<Post[]>({ name: 'posts', defaultMemory: [] })
|
||||||
await postsMemory.write([
|
await postsMemory.write([
|
||||||
{
|
{
|
||||||
id: 0,
|
id: 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user