mirror of
https://github.com/leon-ai/leon.git
synced 2024-12-25 01:31:47 +03:00
fix(bridge/nodejs): types improvements
This commit is contained in:
parent
55b81a3c8f
commit
c361682cab
@ -1,20 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"useDefineForClassFields": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ export type ActionFunction = (params: ActionParams) => Promise<void>
|
||||
*/
|
||||
export interface Answer {
|
||||
key?: string
|
||||
widget?: Widget<unknown>
|
||||
widget?: Widget
|
||||
data?: AnswerData
|
||||
core?: SkillAnswerCoreData
|
||||
}
|
||||
@ -30,7 +30,7 @@ export interface TextAnswer extends Answer {
|
||||
key: string
|
||||
}
|
||||
export interface WidgetAnswer extends Answer {
|
||||
widget: Widget<unknown>
|
||||
widget: Widget
|
||||
key?: string
|
||||
}
|
||||
export type AnswerData = Record<string, string | number> | null
|
||||
|
@ -1,4 +1,4 @@
|
||||
export abstract class WidgetComponent<T> {
|
||||
export abstract class WidgetComponent<T = unknown> {
|
||||
public readonly component: string
|
||||
public readonly props: T
|
||||
|
||||
|
@ -2,25 +2,20 @@ import { type WidgetWrapperProps } from '@leon-ai/aurora'
|
||||
|
||||
import { WidgetComponent } from '@sdk/widget-component'
|
||||
|
||||
export interface WidgetOptions<T> {
|
||||
export interface WidgetOptions<T = unknown> {
|
||||
wrapperProps?: Omit<WidgetWrapperProps, 'children'>
|
||||
params?: T
|
||||
params: T
|
||||
}
|
||||
|
||||
export abstract class Widget<T> {
|
||||
export abstract class Widget<T = unknown> {
|
||||
public wrapperProps: WidgetOptions<T>['wrapperProps']
|
||||
public params: WidgetOptions<T>['params']
|
||||
|
||||
protected constructor(options?: WidgetOptions<T>) {
|
||||
protected constructor(options: WidgetOptions<T>) {
|
||||
if (options?.wrapperProps) {
|
||||
this.wrapperProps = options.wrapperProps
|
||||
}
|
||||
|
||||
if (!options?.params) {
|
||||
this.params = undefined
|
||||
} else {
|
||||
this.params = options.params
|
||||
}
|
||||
this.params = options.params
|
||||
}
|
||||
|
||||
public abstract render(): WidgetComponent<unknown>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { ActionFunction } from '@sdk/types'
|
||||
import { leon } from '@sdk/leon'
|
||||
|
||||
import PlaygroundTestWidget from '../widgets/playground-test'
|
||||
import { PlaygroundTestWidget } from '../widgets/playground-test'
|
||||
|
||||
export const run: ActionFunction = async function () {
|
||||
/**
|
||||
|
@ -7,20 +7,13 @@ interface Params {
|
||||
value2: string
|
||||
}
|
||||
|
||||
export default class PlaygroundTestWidget extends Widget<Params> {
|
||||
constructor(options?: WidgetOptions<Params>) {
|
||||
export class PlaygroundTestWidget extends Widget<Params> {
|
||||
constructor(options: WidgetOptions<Params>) {
|
||||
super(options)
|
||||
}
|
||||
|
||||
public render(): WidgetComponent<unknown> {
|
||||
let children = 'Click me'
|
||||
|
||||
if (this.params) {
|
||||
children = this.params.value1 + ' ' + this.params.value2
|
||||
}
|
||||
|
||||
return new Button({
|
||||
children
|
||||
})
|
||||
public render(): WidgetComponent {
|
||||
const children = this.params.value1 + ' ' + this.params.value2
|
||||
return new Button({ children })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user