Merged in feature/chatbot1 (pull request #223)
Chatbot functionality * baseline working * missing test file * more tests
This commit is contained in:
+85
-48
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
queryapi "queryorchestration/api/queryAPI"
|
||||
"queryorchestration/internal/backgroundtask"
|
||||
"queryorchestration/internal/bot"
|
||||
"queryorchestration/internal/client"
|
||||
clientupdate "queryorchestration/internal/client/update"
|
||||
"queryorchestration/internal/cognitoauth"
|
||||
@@ -40,6 +41,7 @@ import (
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
awsc "queryorchestration/internal/serviceconfig/aws"
|
||||
"queryorchestration/internal/serviceconfig/build"
|
||||
"queryorchestration/internal/serviceconfig/chatbot"
|
||||
"queryorchestration/internal/serviceconfig/objectstore"
|
||||
"queryorchestration/internal/serviceconfig/queue/clientsync"
|
||||
"queryorchestration/internal/uisettings"
|
||||
@@ -54,6 +56,11 @@ type QueryAPIConfig struct {
|
||||
api.BaseConfig
|
||||
clientsync.ClientSyncConfig
|
||||
objectstore.ObjectStoreConfig
|
||||
// Chatbot configuration is loaded from CHATBOT_* env vars and
|
||||
// validated immediately after InitializeConfig. See plan §8 for the
|
||||
// authoritative spec; the embedding lets serviceconfig.InitializeConfig
|
||||
// walk the env tags as part of the standard parse pass.
|
||||
chatbot.ChatbotConfig
|
||||
BackgroundRunner *backgroundtask.Runner
|
||||
}
|
||||
|
||||
@@ -66,54 +73,7 @@ func main() {
|
||||
cfg := &QueryAPIConfig{}
|
||||
|
||||
cfg.RegisterHandlersFunc = func() (*openapi3.T, error) {
|
||||
exp := export.New()
|
||||
col := collector.New(cfg)
|
||||
colupdate := collectorset.New(cfg, &collectorset.Services{
|
||||
Collector: col,
|
||||
})
|
||||
cli := client.New(cfg)
|
||||
cliUpdate := clientupdate.New(cfg, &clientupdate.Services{
|
||||
Client: cli,
|
||||
})
|
||||
doc := document.New(cfg)
|
||||
docup := documentupload.New(cfg)
|
||||
docdownload := documentdownload.New(cfg)
|
||||
docbatch := documentbatch.New(cfg)
|
||||
fieldext := fieldextraction.New(cfg)
|
||||
fld := folder.New(cfg)
|
||||
lbl := label.New(cfg)
|
||||
eul := eula.New(cfg)
|
||||
uiSvc := uisettings.New(cfg)
|
||||
customSchema := customschema.New(cfg, &customschema.SchemaValidator{}, customschema.NewSlogAuditSink(cfg.GetLogger()))
|
||||
|
||||
services := &queryapi.Services{
|
||||
Export: exp,
|
||||
Collector: col,
|
||||
CollectorSet: colupdate,
|
||||
Client: cli,
|
||||
ClientUpdate: cliUpdate,
|
||||
Document: doc,
|
||||
DocumentUpload: docup,
|
||||
DocumentDownload: docdownload,
|
||||
DocumentBatch: docbatch,
|
||||
UISettings: uiSvc,
|
||||
FieldExtraction: fieldext,
|
||||
CustomSchema: customSchema,
|
||||
Folder: fld,
|
||||
Label: lbl,
|
||||
Eula: eul,
|
||||
}
|
||||
|
||||
cons := queryapi.NewControllers(services, cfg)
|
||||
|
||||
queryapi.RegisterHandlers(cfg.Router, cons)
|
||||
|
||||
swagger, err := queryapi.GetSwagger()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading swagger: %w", err)
|
||||
}
|
||||
|
||||
return swagger, nil
|
||||
return registerQueryAPIHandlers(cfg)
|
||||
}
|
||||
|
||||
// Both of these operations (InitializeConfig and InitializeAuthConfig)
|
||||
@@ -127,6 +87,16 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Chatbot config validation runs after InitializeConfig and before
|
||||
// auth init / server.Listen() per plan §8. Range checks on the
|
||||
// numeric fields are not enforceable by env tags alone, so a
|
||||
// dedicated Validate is invoked here and bails the process on
|
||||
// invalid input the same way other config-validation failures do.
|
||||
if err := cfg.ChatbotConfig.Validate(); err != nil {
|
||||
slog.Error("chatbot config validation failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Authentication specific config.
|
||||
cfg.BaseURL = fmt.Sprintf("%s:%d", cfg.BaseURL, cfg.Port)
|
||||
errorInitializingAuthConfig := cfg.InitializeAuthConfig(cfg.BaseURL, cfg.GetLogger())
|
||||
@@ -176,3 +146,70 @@ func main() {
|
||||
|
||||
server.Listen()
|
||||
}
|
||||
|
||||
// registerQueryAPIHandlers builds the queryAPI service graph, registers
|
||||
// the OpenAPI-driven echo router, and returns the swagger doc the
|
||||
// server uses for request validation. Extracted from main() so the
|
||||
// per-package average-complexity linter does not flag main().
|
||||
func registerQueryAPIHandlers(cfg *QueryAPIConfig) (*openapi3.T, error) {
|
||||
services, err := buildQueryAPIServices(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cons := queryapi.NewControllers(services, cfg)
|
||||
queryapi.RegisterHandlers(cfg.Router, cons)
|
||||
swagger, err := queryapi.GetSwagger()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading swagger: %w", err)
|
||||
}
|
||||
return swagger, nil
|
||||
}
|
||||
|
||||
// buildQueryAPIServices constructs every service that backs the
|
||||
// generated controller. Bot construction validates the chatbot config
|
||||
// a second time so non-main callers (tests, alternate entry points)
|
||||
// inherit the same gate as main().
|
||||
func buildQueryAPIServices(cfg *QueryAPIConfig) (*queryapi.Services, error) {
|
||||
exp := export.New()
|
||||
col := collector.New(cfg)
|
||||
colupdate := collectorset.New(cfg, &collectorset.Services{
|
||||
Collector: col,
|
||||
})
|
||||
cli := client.New(cfg)
|
||||
cliUpdate := clientupdate.New(cfg, &clientupdate.Services{
|
||||
Client: cli,
|
||||
})
|
||||
doc := document.New(cfg)
|
||||
docup := documentupload.New(cfg)
|
||||
docdownload := documentdownload.New(cfg)
|
||||
docbatch := documentbatch.New(cfg)
|
||||
fieldext := fieldextraction.New(cfg)
|
||||
fld := folder.New(cfg)
|
||||
lbl := label.New(cfg)
|
||||
eul := eula.New(cfg)
|
||||
uiSvc := uisettings.New(cfg)
|
||||
customSchema := customschema.New(cfg, &customschema.SchemaValidator{}, customschema.NewSlogAuditSink(cfg.GetLogger()))
|
||||
botSvc, err := bot.New(cfg.ChatbotConfig, cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error constructing bot service: %w", err)
|
||||
}
|
||||
|
||||
return &queryapi.Services{
|
||||
Export: exp,
|
||||
Collector: col,
|
||||
CollectorSet: colupdate,
|
||||
Client: cli,
|
||||
ClientUpdate: cliUpdate,
|
||||
Document: doc,
|
||||
DocumentUpload: docup,
|
||||
DocumentDownload: docdownload,
|
||||
DocumentBatch: docbatch,
|
||||
UISettings: uiSvc,
|
||||
FieldExtraction: fieldext,
|
||||
CustomSchema: customSchema,
|
||||
Folder: fld,
|
||||
Label: lbl,
|
||||
Eula: eul,
|
||||
Bot: botSvc,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user