From f38a2e4eb408b4d66c86313011cbbdee0537fd66 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 21 May 2024 20:45:32 +0800 Subject: [PATCH 1/8] chore: Set full configuration by default for list widget Set the full configuration by default for the list widget. This is a temporary solution and will be removed in the future. The full configuration should be set when the list is created. --- widgets/list/list.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/widgets/list/list.go b/widgets/list/list.go index 3eab15ab..29efc8bf 100644 --- a/widgets/list/list.go +++ b/widgets/list/list.go @@ -219,8 +219,17 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool, quer return nil, err } - // full width default value - if _, has := dsl.Config["full"]; !has { + // ** WARNING ** + // set the full configuration by default + // Temporary solution, Will be removed in the future + // should be set when the list is created + config := map[string]interface{}{} + if dsl.Config != nil { + for key, value := range dsl.Config { + config[key] = value + } + } + if _, has := config["full"]; !has { dsl.Config["full"] = true } @@ -237,7 +246,7 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool, quer onChange := map[string]interface{}{} // Hooks setting["fields"] = fields - setting["config"] = dsl.Config + setting["config"] = config replacements := maps.Map{} if query != nil { From 1a1ffabbd81e2cbac5f926cfc07c646cda61e390 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 23 May 2024 06:48:12 +0800 Subject: [PATCH 2/8] feat: Add hideLabel option to component and column DSL Add the hideLabel option to the component and column DSLs. This allows hiding the label for the respective widgets. The hideLabel option is set to true in the component and column DSLs when necessary. --- widgets/component/component.go | 5 +++++ widgets/component/types.go | 9 +++++---- widgets/field/column.go | 4 ++++ widgets/field/types.go | 15 ++++++++------- widgets/form/form.go | 19 ++++++++++++++----- widgets/list/list.go | 2 +- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/widgets/component/component.go b/widgets/component/component.go index c0274248..4d0a36f0 100644 --- a/widgets/component/component.go +++ b/widgets/component/component.go @@ -27,6 +27,11 @@ func (dsl DSL) Map() map[string]interface{} { "type": dsl.Type, "props": map[string]interface{}(dsl.Props), } + + if dsl.HideLabel { + res["hideLabel"] = true + } + if dsl.Bind != "" { res["bind"] = dsl.Bind } diff --git a/widgets/component/types.go b/widgets/component/types.go index c05c38c5..c2df429a 100644 --- a/widgets/component/types.go +++ b/widgets/component/types.go @@ -2,10 +2,11 @@ package component // DSL the component DSL type DSL struct { - Bind string `json:"bind,omitempty"` - Type string `json:"type,omitempty"` - Compute *Compute `json:"compute,omitempty"` - Props PropsDSL `json:"props,omitempty"` + Bind string `json:"bind,omitempty"` + HideLabel bool `json:"hideLabel,omitempty"` + Type string `json:"type,omitempty"` + Compute *Compute `json:"compute,omitempty"` + Props PropsDSL `json:"props,omitempty"` } // Actions the actions diff --git a/widgets/field/column.go b/widgets/field/column.go index 00346cf7..eef798c3 100644 --- a/widgets/field/column.go +++ b/widgets/field/column.go @@ -112,6 +112,10 @@ func (column ColumnDSL) Map() map[string]interface{} { "bind": column.Bind, } + if column.HideLabel { + res["hideLabel"] = true + } + if column.Data != nil { res["data"] = map[string]interface{}{"process": column.Data.Process, "query": column.Data.Query} } diff --git a/widgets/field/types.go b/widgets/field/types.go index 58fd1daa..10f5b958 100644 --- a/widgets/field/types.go +++ b/widgets/field/types.go @@ -18,13 +18,14 @@ type CloudProps map[string]component.CloudPropsDSL // ColumnDSL the field column dsl type ColumnDSL struct { - ID string `json:"id,omitempty"` - Data *component.CloudPropsDSL `json:"$data,omitempty"` - Key string `json:"key,omitempty"` - Bind string `json:"bind,omitempty"` - Link string `json:"link,omitempty"` - View *component.DSL `json:"view,omitempty"` - Edit *component.DSL `json:"edit,omitempty"` + ID string `json:"id,omitempty"` + Data *component.CloudPropsDSL `json:"$data,omitempty"` + Key string `json:"key,omitempty"` + Bind string `json:"bind,omitempty"` + Link string `json:"link,omitempty"` + HideLabel bool `json:"hideLabel,omitempty"` + View *component.DSL `json:"view,omitempty"` + Edit *component.DSL `json:"edit,omitempty"` } type aliasColumnDSL ColumnDSL diff --git a/widgets/form/form.go b/widgets/form/form.go index 5a4e46d3..58ae07b4 100644 --- a/widgets/form/form.go +++ b/widgets/form/form.go @@ -264,15 +264,24 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool) (map return nil, err } - // full width default value - if _, has := dsl.Config["full"]; !has { - dsl.Config["full"] = true + // ** WARNING ** + // set the full configuration by default + // Temporary solution, Will be removed in the future + // should be set when the list is created + config := map[string]interface{}{} + if dsl.Config != nil { + for key, value := range dsl.Config { + config[key] = value + } + } + if _, has := config["full"]; !has { + config["full"] = true } // Merge the layout config if layout.Config != nil { for key, value := range layout.Config { - dsl.Config[key] = value + config[key] = value } } @@ -289,7 +298,7 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool) (map onChange := map[string]interface{}{} // Hooks setting["fields"] = fields - setting["config"] = dsl.Config + setting["config"] = config for _, cProp := range dsl.CProps { err := cProp.Replace(setting, func(cProp component.CloudPropsDSL) interface{} { diff --git a/widgets/list/list.go b/widgets/list/list.go index 29efc8bf..e76112e7 100644 --- a/widgets/list/list.go +++ b/widgets/list/list.go @@ -230,7 +230,7 @@ func (dsl *DSL) Xgen(data map[string]interface{}, excludes map[string]bool, quer } } if _, has := config["full"]; !has { - dsl.Config["full"] = true + config["full"] = true } setting := map[string]interface{}{} From 1f4e9e5a16c7ec03603a28831686b3594e2baa9d Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 25 May 2024 20:17:25 +0800 Subject: [PATCH 3/8] feat: Add SelectModel command to DSL Add the SelectModel command to the DSL, allowing the selection of a specific model. This command takes a model name as input and sets the AI to use that model. It returns a success message with a status code of 200 if the selection is successful. --- neo/neo.go | 43 +++++++++++++++++++++++++++++++++++++++++-- neo/types.go | 1 + 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/neo/neo.go b/neo/neo.go index 6c8dbc28..0b610c01 100644 --- a/neo/neo.go +++ b/neo/neo.go @@ -130,6 +130,29 @@ func (neo *DSL) API(router *gin.Engine, path string) error { } switch cmd { + + case "ModelList": + c.JSON(200, gin.H{"data": neo.Models, "code": 200}) + c.Done() + + case "SelectModel": + model, ok := payload["model"].(string) + if !ok { + c.JSON(400, gin.H{"message": "model is required", "code": 400}) + c.Done() + return + } + + err := neo.Select(model) + if err != nil { + c.JSON(500, gin.H{"message": err.Error(), "code": 500}) + c.Done() + return + } + + c.JSON(200, gin.H{"message": "success", "code": 200}) + c.Done() + case "ExitCommandMode": err := command.Exit(sid) if err != nil { @@ -524,11 +547,17 @@ func (neo *DSL) getGuardHandlers() ([]gin.HandlerFunc, error) { // NewAI create a new AI func (neo *DSL) newAI() error { - if neo.Connector == "" { - ai, err := openai.NewMoapi("gpt-3.5-turbo") + if neo.Connector == "" || strings.HasPrefix(neo.Connector, "moapi") { + model := "gpt-3.5-turbo" + if neo.Connector != "" { + model = strings.TrimPrefix(neo.Connector, "moapi:") + } + + ai, err := openai.NewMoapi(model) if err != nil { return err } + neo.AI = ai return nil } @@ -550,6 +579,16 @@ func (neo *DSL) newAI() error { return fmt.Errorf("%s connector %s not support, should be a openai", neo.ID, neo.Connector) } +// Select select the model +func (neo *DSL) Select(model string) error { + ai, err := openai.NewMoapi(model) + if err != nil { + return err + } + neo.AI = ai + return nil +} + // newConversation create a new conversation func (neo *DSL) newConversation() error { diff --git a/neo/types.go b/neo/types.go index 37129e96..f6846caa 100644 --- a/neo/types.go +++ b/neo/types.go @@ -22,6 +22,7 @@ type DSL struct { Prompts []aigc.Prompt `json:"prompts,omitempty"` Allows []string `json:"allows,omitempty"` Command Command `json:"command,omitempty"` + Models []string `json:"models,omitempty"` AI aigc.AI `json:"-" yaml:"-"` Conversation conversation.Conversation `json:"-" yaml:"-"` GuardHandlers []gin.HandlerFunc `json:"-" yaml:"-"` From 8bf78c65d47d54a6f55a06db2a731bc87e50606d Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 31 May 2024 17:11:11 +0800 Subject: [PATCH 4/8] Update installation instructions in README --- README.md | 25 ++----------------------- README.zh-CN.md | 25 ++----------------------- 2 files changed, 4 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 22685229..4a65ffa1 100644 --- a/README.md +++ b/README.md @@ -81,13 +81,9 @@ Yao has a built-in data management system. By writing **JSON** to describe the i ## Install -Run the script under terminal: (MacOS/Linux) +Latest Version download and installation: -```bash -curl -fsSL https://website.yaoapps.com/install.sh | bash -``` - -For Windows users, please refer to the Installation and Debugging chapter: [Installation and debugging](https://yaoapps.com/en-US/doc/Introduction/Install) +https://github.com/YaoApp/xgen-dev-app/blob/main/README.md ## Getting Started @@ -109,23 +105,6 @@ yao start # Start installation - Password: **A123456p+** -### Download a project - -Create a new project directory, enter the project directory, run the `yao get` command, and download the application code. - -```bash -mkdir -p /data/app # create project directory -cd /data/app # Enter the project directory -yao get yaoapp/demo-plm # download demo-plm -yao start # Start installation -``` - -**Default Account** - -- User: **xiang@iqka.com** - -- Password: **A123456p+** - ## About Yao Yao's name is derived from the Chinese character **爻 (yáo)**, the basic symbol that makes up the Eight Trigrams. The Eight Trigrams is a symbol system created by the ancient god Fuxi after observing and summarizing the laws of nature, which can refer to everything. Yao has two states of yin and yang, like 0 and 1. The transformation of yin and yang of Yao drives the replacement of Eight Trigrams, so as to summarize and record the development law of things. diff --git a/README.zh-CN.md b/README.zh-CN.md index b67a94e4..4b702877 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -50,13 +50,9 @@ Yao 内置了一套数据管理系统,通过编写 **JSON** 描述界面布局 ## 安装 -在终端下运行脚本: ( MacOS / Linux ) +Yao v0.10.4 使用说明 -```bash -curl -fsSL https://website.yaoapps.com/install.sh | bash -``` - -Windows 用户请参考安装调试章节: [安装调试](https://yaoapps.com/doc/%E4%BB%8B%E7%BB%8D/%E5%AE%89%E8%A3%85%E8%B0%83%E8%AF%95) +https://github.com/YaoApp/xgen-dev-app/blob/main/README.zh-CN.md ## 入门指南 @@ -82,23 +78,6 @@ yao start # 启动安装界面 ![安装界面](docs/yao-setup-step2.jpg) -#### 下载已上架应用 - -新建一个项目目录,进入项目目录,运行 `yao get` 命令, 下载应用代码。 - -```bash -mkdir -p /data/app # 创建应用目录 -cd /data/app # 进入应用目录 -yao get yaoapp/demo-plm # 下载 demo-plm -yao start # 启动安装界面 -``` - -**默认账号** - -- 用户名: **xiang@iqka.com** - -- 密码: **A123456p+** - ## 关于 Yao Yao 的名字源于汉字**爻(yáo)**,是构成八卦的基本符号。八卦,是上古大神伏羲观测总结自然规律后,创造的一个可以指代万事万物的符号体系。爻,有阴阳两种状态,就像 0 和 1。爻的阴阳转换,驱动八卦更替,以此来总结记录事物的发展规律。 From 55ca180f7f260e817ad9fcd1a5029ac3641908f2 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 5 Jun 2024 14:59:25 +0800 Subject: [PATCH 5/8] [add] TypeScript import support (experimental) - When YAO_RUNTIME_IMPORT is set to true, TypeScript import will be enabled. --- config/types.go | 4 ++++ runtime/runtime.go | 1 + 2 files changed, 5 insertions(+) diff --git a/config/types.go b/config/types.go index bfd22d7e..58df739d 100644 --- a/config/types.go +++ b/config/types.go @@ -65,4 +65,8 @@ type Runtime struct { HeapSizeRelease uint64 `json:"heapSizeRelease,omitempty" env:"YAO_RUNTIME_HEAP_RELEASE" envDefault:"52428800"` // the isolate will be re-created when reaching this value, and the default value is 52428800 (50M) HeapAvailableSize uint64 `json:"heapAvailableSize,omitempty" env:"YAO_RUNTIME_HEAP_AVAILABLE" envDefault:"524288000"` // the isolate will be re-created when the available size is smaller than this value, and the default value is 524288000 (500M) Precompile bool `json:"precompile,omitempty" env:"YAO_RUNTIME_PRECOMPILE" envDefault:"false"` // if true compile scripts when the VM is created. this will increase the load time, but the script will run faster. the default value is false + + // The following options are experimental features and not stable. + // They may be removed once the features become stable. Please do not use them in a production environment. + Import bool `json:"import,omitempty" env:"YAO_RUNTIME_IMPORT" envDefault:"false"` // If true, TypeScript import will be enabled. Default value is false. } diff --git a/runtime/runtime.go b/runtime/runtime.go index 35b64295..6986ade4 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -19,6 +19,7 @@ func Start(cfg config.Config) error { Mode: cfg.Runtime.Mode, DefaultTimeout: cfg.Runtime.DefaultTimeout, ContextTimeout: cfg.Runtime.ContextTimeout, + Import: cfg.Runtime.Import, } err := v8.Start(option) From 26189fd61f7654f16e6f751da7673742862b8024 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 6 Jun 2024 15:44:28 +0800 Subject: [PATCH 6/8] feat: Clear modules before loading shared library Clear the modules before loading the shared library to ensure a clean state. This is necessary to avoid any conflicts or issues with previously loaded modules. --- script/script.go | 1 + 1 file changed, 1 insertion(+) diff --git a/script/script.go b/script/script.go index 2c8c08a6..68cfd3dd 100644 --- a/script/script.go +++ b/script/script.go @@ -11,6 +11,7 @@ import ( // Load 加载共享库 func Load(cfg config.Config) error { + v8.CLearModules() exts := []string{"*.js", "*.ts"} err := application.App.Walk("scripts", func(root, file string, isdir bool) error { if isdir { From 8583f1a0f0c050e16dfe13b2147a38675785f3c5 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 11 Jun 2024 10:40:19 +0800 Subject: [PATCH 7/8] chore: Deprecate $slot and $prop in favor of $slots and $props Deprecate the usage of $slot and $prop in the code and introduce $slots and $props as their replacements. This change ensures consistency and improves clarity in the codebase. --- sui/core/build.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sui/core/build.go b/sui/core/build.go index a72838ab..8da61d61 100644 --- a/sui/core/build.go +++ b/sui/core/build.go @@ -72,11 +72,13 @@ func (page *Page) BuildForImport(option *BuildOption, slots map[string]interface for k, v := range slots { slotvars[k] = v } - data["$slot"] = slotvars + data["$slot"] = slotvars // Will be deprecated use $slots instead + data["$slots"] = slotvars } if attrs != nil { - data["$prop"] = attrs + data["$prop"] = attrs // Will be deprecated use $props instead + data["$props"] = attrs page.Attrs = attrs } @@ -195,7 +197,10 @@ func (page *Page) parse(doc *goquery.Document, option *BuildOption, warnings []s } val := attr.Val if page.Attrs != nil { - parentProps := Data{"$prop": page.Attrs} + parentProps := Data{ + "$prop": page.Attrs, // Will be deprecated use $props instead + "$props": page.Attrs, + } val, _ = parentProps.ReplaceUse(slotRe, val) } attrs[attr.Key] = val From 971246d0909e29888d550cc47baa72e6a404cfa4 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 11 Jun 2024 17:26:37 +0800 Subject: [PATCH 8/8] chore: Update cssRe regular expression to include hyphen in selectors --- sui/core/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sui/core/build.go b/sui/core/build.go index 8da61d61..0f865738 100644 --- a/sui/core/build.go +++ b/sui/core/build.go @@ -13,7 +13,7 @@ import ( ) var slotRe = regexp.MustCompile(`\[\{([^\}]+)\}\]`) -var cssRe = regexp.MustCompile(`([\.a-z0-9A-Z# ]+)\{`) +var cssRe = regexp.MustCompile(`([\.a-z0-9A-Z-:# ]+)\{`) // Build is the struct for the public func (page *Page) Build(option *BuildOption) (*goquery.Document, []string, error) {