diff --git a/app/src/js/client.js b/app/src/js/client.js index 2d073e9c..c5a05b3c 100644 --- a/app/src/js/client.js +++ b/app/src/js/client.js @@ -79,7 +79,15 @@ export default class Client { const root = createRoot(container) // 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) => { diff --git a/bridges/nodejs/src/sdk/aurora/button.ts b/bridges/nodejs/src/sdk/aurora/button.ts index f070453c..e4fcd2e1 100644 --- a/bridges/nodejs/src/sdk/aurora/button.ts +++ b/bridges/nodejs/src/sdk/aurora/button.ts @@ -1,14 +1,12 @@ +import { Widget } from '../widget' + // TODO: contains the button API. rendering engine <-> SDK -interface Options { +interface ButtonOptions { text: string } -export class Button { - private readonly text: string - - constructor(options: Options) { - this.text = options.text - - console.log('Button constructor', this.text) +export class Button extends Widget { + public constructor(options: ButtonOptions) { + super(options) } } diff --git a/bridges/nodejs/src/sdk/memory.ts b/bridges/nodejs/src/sdk/memory.ts index c13cdcc5..2f5e271d 100644 --- a/bridges/nodejs/src/sdk/memory.ts +++ b/bridges/nodejs/src/sdk/memory.ts @@ -8,7 +8,7 @@ interface MemoryOptions { defaultMemory?: T } -export class Memory { +export class Memory { private readonly memoryPath: string | undefined private readonly name: string private readonly defaultMemory: T | undefined @@ -55,12 +55,14 @@ export class Memory { * Read the memory * @example read() */ - public async read(): Promise { - try { - if (!this.memoryPath) { - return - } + public async read(): Promise { + if (!this.memoryPath) { + 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)) { await this.clear() } diff --git a/bridges/nodejs/src/sdk/types.ts b/bridges/nodejs/src/sdk/types.ts index b56d86a9..f837c124 100644 --- a/bridges/nodejs/src/sdk/types.ts +++ b/bridges/nodejs/src/sdk/types.ts @@ -3,17 +3,10 @@ */ import type { ActionParams, IntentObject } from '@/core/brain/types' -import type { Button } from '@sdk/aurora/button' - export type { ActionParams, IntentObject } export type ActionFunction = (params: ActionParams) => Promise -/** - * Aurora - */ -export type AuroraComponent = Button // TODO - /** * Answer types */ diff --git a/bridges/nodejs/src/sdk/widget.ts b/bridges/nodejs/src/sdk/widget.ts index edc47fcb..8a32e90c 100644 --- a/bridges/nodejs/src/sdk/widget.ts +++ b/bridges/nodejs/src/sdk/widget.ts @@ -1,23 +1,9 @@ -import type { AuroraComponent } from '@sdk/types' +export abstract class Widget { + public readonly type: string + public readonly options: T -interface SerializedAuroraComponent { - type: string - props: Record -} - -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) + protected constructor(options: T) { + this.type = this.constructor.name + this.options = options } } diff --git a/scripts/check.js b/scripts/check.js index b65876c7..5e99464e 100644 --- a/scripts/check.js +++ b/scripts/check.js @@ -159,11 +159,11 @@ dotenv.config() if (Math.round(freeRAMInGB) < MINIMUM_REQUIRED_RAM) { report.can_run.v = false 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 { LogHelper.success( - `Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB` + `Free RAM: ${freeRAMInGB} GB | Total RAM: ${totalRAMInGB} GB` ) } diff --git a/server/src/pre-check.ts b/server/src/pre-check.ts index 263ed577..c97c8b40 100644 --- a/server/src/pre-check.ts +++ b/server/src/pre-check.ts @@ -101,11 +101,11 @@ const GLOBAL_DATA_SCHEMAS = { if (freeRAMInGB < MINIMUM_REQUIRED_RAM) { 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 { 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` ) } diff --git a/skills/leon/age/src/actions/run.ts b/skills/leon/age/src/actions/run.ts index aa2a060b..fa4004ea 100644 --- a/skills/leon/age/src/actions/run.ts +++ b/skills/leon/age/src/actions/run.ts @@ -2,7 +2,6 @@ import utility from 'utility' // TODO import type { ActionFunction } from '@sdk/types' import { leon } from '@sdk/leon' -import { Widget } from '@sdk/widget' import { Network } from '@sdk/network' import { Button } from '@sdk/aurora/button' import { Memory } from '@sdk/memory' @@ -21,20 +20,21 @@ export const run: ActionFunction = async function () { const button = new Button({ text: 'Hello world from action skill' }) - const widget = new Widget([button]) - - await leon.answer({ widget }) + await leon.answer({ widget: button }) /// - const otherSkillMemory = new Memory({ + const otherSkillMemory = new Memory({ name: 'productivity:todo_list:db' }) + try { + const todoLists = await otherSkillMemory.read() + console.log('todoLists', todoLists) + } catch { + console.log('todoLists', []) + } + const postsMemory = new Memory({ name: 'posts', defaultMemory: [] }) - const todoLists = await otherSkillMemory.read() - - console.log('todoLists', todoLists) - await postsMemory.write([ { id: 0,