Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions apps/cliq-app/config/settings_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type AppSettings struct {
CliqHubBaseURL string `mapstructure:"cliq_hub_base_url"`
CliqHubBaseURL string `mapstructure:"cliq_hub_base_url"`
}

type SettingsService struct {
Expand All @@ -24,7 +24,7 @@ func NewSettingsService() (*SettingsService, error) {
vp.SetEnvPrefix("CLIQ")
vp.AutomaticEnv()

vp.SetDefault("cliq_hub_base_url", "http://localhost:8080")
vp.SetDefault("cliq_hub_base_url", "http://localhost:8080")

cfgDir, err := os.UserConfigDir()
if err != nil {
Expand Down Expand Up @@ -52,38 +52,38 @@ func NewSettingsService() (*SettingsService, error) {
}

func (s *SettingsService) Load() (*AppSettings, error) {
var cfg AppSettings
if err := s.vp.Unmarshal(&cfg); err != nil {
return nil, fmt.Errorf("unmarshal settings: %w", err)
}
return &cfg, nil
var cfg AppSettings
if err := s.vp.Unmarshal(&cfg); err != nil {
return nil, fmt.Errorf("unmarshal settings: %w", err)
}
return &cfg, nil
}

func (s *SettingsService) Save(in *AppSettings) error {
if in == nil {
return errors.New("settings is nil")
}
if err := validateURL(in.CliqHubBaseURL); err != nil {
return err
}
s.vp.Set("cliq_hub_base_url", in.CliqHubBaseURL)
return s.vp.WriteConfigAs(s.configFile)
if in == nil {
return errors.New("settings is nil")
}
if err := validateURL(in.CliqHubBaseURL); err != nil {
return err
}
s.vp.Set("cliq_hub_base_url", in.CliqHubBaseURL)
return s.vp.WriteConfigAs(s.configFile)
}

func (s *SettingsService) Update(partial map[string]any) error {
if partial == nil {
return nil
}
// Validate known keys
if v, ok := partial["cliq_hub_base_url"]; ok {
if str, ok2 := v.(string); ok2 {
if err := validateURL(str); err != nil {
return err
}
s.vp.Set("cliq_hub_base_url", str)
}
}
return s.vp.WriteConfigAs(s.configFile)
if v, ok := partial["cliq_hub_base_url"]; ok {
if str, ok2 := v.(string); ok2 {
if err := validateURL(str); err != nil {
return err
}
s.vp.Set("cliq_hub_base_url", str)
}
}
return s.vp.WriteConfigAs(s.configFile)
}

func validateURL(u string) error {
Expand Down
52 changes: 26 additions & 26 deletions apps/cliq-hub-backend/cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package main

import (
"log"
"net/http"
"os"
"log"
"net/http"
"os"

"cliq-hub-backend/internal/config"
"cliq-hub-backend/internal/http/router"
"cliq-hub-backend/internal/llm"
"cliq-hub-backend/internal/config"
"cliq-hub-backend/internal/http/router"
"cliq-hub-backend/internal/llm"
)

func main() {
cfg, err := config.Load()
if err != nil {
log.Fatalf("config error: %v", err)
}
cfg, err := config.Load()
if err != nil {
log.Fatalf("config error: %v", err)
}

client, err := llm.NewClient(cfg)
if err != nil {
log.Fatalf("llm client init error: %v", err)
}
client, err := llm.NewClient(cfg)
if err != nil {
log.Fatalf("llm client init error: %v", err)
}

debugMode := os.Getenv("GIN_MODE") != "release"
r := router.New(client, debugMode)
debugMode := os.Getenv("GIN_MODE") != "release"
r := router.New(client, debugMode)

port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}

srv := &http.Server{Addr: ":" + port, Handler: r}
log.Printf("server listening on :%s", port)
if err := srv.ListenAndServe(); err != nil && err.Error() != "http: Server closed" {
log.Fatalf("server error: %v", err)
}
}
srv := &http.Server{Addr: ":" + port, Handler: r}
log.Printf("server listening on :%s", port)
if err := srv.ListenAndServe(); err != nil && err.Error() != "http: Server closed" {
log.Fatalf("server error: %v", err)
}
}
36 changes: 18 additions & 18 deletions apps/cliq-hub-backend/internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package config

import (
"errors"
"os"
"errors"
"os"
)

type Config struct {
LLMBaseURL string
LLMAPIKey string
LLMModel string
LLMBaseURL string
LLMAPIKey string
LLMModel string
}

func Load() (*Config, error) {
cfg := &Config{
LLMBaseURL: os.Getenv("LLM_BASE_URL"),
LLMAPIKey: os.Getenv("LLM_API_KEY"),
LLMModel: os.Getenv("LLM_MODEL"),
}
if cfg.LLMAPIKey == "" {
return nil, errors.New("LLM_API_KEY is required")
}
if cfg.LLMModel == "" {
return nil, errors.New("LLM_MODEL is required")
}
return cfg, nil
}
cfg := &Config{
LLMBaseURL: os.Getenv("LLM_BASE_URL"),
LLMAPIKey: os.Getenv("LLM_API_KEY"),
LLMModel: os.Getenv("LLM_MODEL"),
}
if cfg.LLMAPIKey == "" {
return nil, errors.New("LLM_API_KEY is required")
}
if cfg.LLMModel == "" {
return nil, errors.New("LLM_MODEL is required")
}
return cfg, nil
}
20 changes: 10 additions & 10 deletions apps/cliq-hub-backend/internal/errors/api.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package errors

type APIError struct {
Error string `json:"error"`
Message string `json:"message"`
Meta map[string]interface{} `json:"meta,omitempty"`
Error string `json:"error"`
Message string `json:"message"`
Meta map[string]interface{} `json:"meta,omitempty"`
}

func New(code, msg string) APIError {
return APIError{Error: code, Message: msg}
return APIError{Error: code, Message: msg}
}

func (e APIError) WithMeta(key string, value interface{}) APIError {
if e.Meta == nil {
e.Meta = make(map[string]interface{})
}
e.Meta[key] = value
return e
}
if e.Meta == nil {
e.Meta = make(map[string]interface{})
}
e.Meta[key] = value
return e
}
34 changes: 17 additions & 17 deletions apps/cliq-hub-backend/internal/template/model.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package template

type Template struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Version string `yaml:"version"`
Author string `yaml:"author"`
CliqTemplateVersion string `yaml:"cliq_template_version"`
Cmds []Cmd `yaml:"cmds"`
Name string `yaml:"name"`
Description string `yaml:"description"`
Version string `yaml:"version"`
Author string `yaml:"author"`
CliqTemplateVersion string `yaml:"cliq_template_version"`
Cmds []Cmd `yaml:"cmds"`
}

type Cmd struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Command string `yaml:"command"`
Variables []Variable `yaml:"variables"`
Name string `yaml:"name"`
Description string `yaml:"description"`
Command string `yaml:"command"`
Variables []Variable `yaml:"variables"`
}

type Variable struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Label string `yaml:"label"`
Description string `yaml:"description"`
Required bool `yaml:"required"`
Options map[string]interface{} `yaml:"options,omitempty"`
}
Name string `yaml:"name"`
Type string `yaml:"type"`
Label string `yaml:"label"`
Description string `yaml:"description"`
Required bool `yaml:"required"`
Options map[string]interface{} `yaml:"options,omitempty"`
}
6 changes: 3 additions & 3 deletions apps/cliq-hub-backend/internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package version

const (
TemplateVersion = "1.0"
CliqTemplateSpecVersion = "1.0"
)
TemplateVersion = "1.0"
CliqTemplateSpecVersion = "1.0"
)
54 changes: 27 additions & 27 deletions packages/cliqfile/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func TestValidateRoot(t *testing.T) {
expectedError string
}{
{
name: "Empty document",
yaml: "",
name: "Empty document",
yaml: "",
expectedError: "Empty document",
},
{
name: "Root not a mapping",
yaml: "- item1",
name: "Root not a mapping",
yaml: "- item1",
expectedError: "Root must be a mapping (object)",
},
{
Expand Down Expand Up @@ -326,7 +326,7 @@ cmds:
}

func TestValidateVariableUsage(t *testing.T) {
yamlStr := `
yamlStr := `
name: Test
description: Test
version: 1.0
Expand All @@ -341,28 +341,28 @@ cmds:
type: string
label: Defined
`
errors, err := Validate([]byte(yamlStr))
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
foundUnused := false
foundUndefined := false
errors, err := Validate([]byte(yamlStr))
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
foundUnused := false
foundUndefined := false

for _, e := range errors {
if e.Field == "command" && e.Message == "Variable 'unused_var' used in command string but not defined in variables" {
foundUndefined = true
}
if e.Field == "variables" && e.Message == "Variable 'defined_var' defined but not used in command string" {
foundUnused = true
}
}
for _, e := range errors {
if e.Field == "command" && e.Message == "Variable 'unused_var' used in command string but not defined in variables" {
foundUndefined = true
}
if e.Field == "variables" && e.Message == "Variable 'defined_var' defined but not used in command string" {
foundUnused = true
}
}

if !foundUndefined {
t.Error("Expected error about undefined variable usage")
}
if !foundUnused {
t.Error("Expected error about unused variable definition")
}
if !foundUndefined {
t.Error("Expected error about undefined variable usage")
}
if !foundUnused {
t.Error("Expected error about unused variable definition")
}
}

func TestValidateNoVariables(t *testing.T) {
Expand All @@ -385,8 +385,8 @@ cmds:
t.Errorf("Expected no errors, got %v", errors)
}

// Also test with variables: []
validYAML2 := `
// Also test with variables: []
validYAML2 := `
name: My Template
description: A description
version: 1.0
Expand Down
Loading