Commit Graph
6 Commits
Author SHA1 Message Date
rogee ee8fbb3df2 Fix duplicate migration version numbers (000048/000049)
Renumber migrations from merged feature/ai-feature-activation branch
to resolve golang-migrate duplicate version conflict:
- 000048_add_captain_auto_reply_rules → 000050
- 000049_add_article_embedding_vector → 000051

Both migrations were already applied to the database; schema_migrations
version updated from 49 to 51 to reflect the new numbering.
2026-07-08 16:28:40 +08:00
rogee c72e359e48 Phase 3.1: Help Center semantic search with pgvector
- ArticleEmbeddingRepo (new): Upsert, GetByArticleID, DeleteByArticleID,
  SearchByEmbedding using pgvector cosine distance (vector_embedding column)
- ArticleEmbedding model: add VectorEmbedding pgvector.Vector field
  alongside existing JSONB Embedding (backward compatible)
- ArticleService: add SemanticSearch() — generates query embedding via LLM,
  searches articles by cosine similarity; add GenerateEmbedding() — creates
  and stores article embedding from title+description+content
- ArticleHandler: add SemanticSearch endpoint
  GET /portals/:portal_id/articles/semantic_search?query=...
- bootstrap.go: inject articleEmbeddingRepo + llmProvider into ArticleService
- router.go: register /articles/semantic_search route
- migration 000049: add vector(1536) column to article_embeddings table,
  create ivfflat index, migrate existing JSONB data to vector format

Verified: go build + go vet + go test all pass
2026-07-08 15:38:08 +08:00
rogee b769b9a3e4 Phase 2: AutoReplyRule integration + AgentBot Captain type
AutoReplyRule complete integration:
- bootstrap.go: instantiate AutoReplyRuleService + AutoReplyListener,
  register listener on channel dispatcher for message.created events
- router.go: register /captain/auto_reply_rules CRUD + /evaluate routes
- auto_reply_rule_handler.go: fix c.Param(id) → c.Param(account_id),
  override evalCtx.AccountID from path param
- auto_reply_rule_service.go: add JSON tags to AutoReplyEvaluationContext
  for correct request body binding
- auto_reply_listener.go (new): EventListener that triggers on incoming
  messages, evaluates active rules, composes reply (static/LLM/mixed),
  respects DelaySeconds and OneTimeOnly flags, sends via MessageService
- migration 000048: create captain_auto_reply_rules table

AgentBot + Captain integration:
- agent_bot_listener.go: add captainConvSvc field + SetCaptainConversationService
  method. In HandleEvent loop, check bot.BotType == captain and route
  to CaptainConversationService.BuildConversationResponseByAccount
  instead of webhook push. Extract assistant_id from bot.Config JSONB,
  extract conversation_id from event data.
- bootstrap.go: inject captainConversationService into agentBotListener

CaptainConversationService improvement:
- generateConversationResponse: use assistant config for system prompt,
  model name, and temperature instead of hardcoded values

Verified:
- go build ./... passes
- go vet passes on all internal packages
- go test passes (service + repository + llm, SQLite mode)
- Auto-reply CRUD: create/get/update/delete all work
- Auto-reply evaluate: correctly matches hello → should_reply=true,
  correctly rejects non-matching message
- Existing routes unaffected (assistants, RAG, conversation respond)
- Migration 000048 creates captain_auto_reply_rules table successfully
2026-07-08 15:38:08 +08:00
rogee 10cc300f31 Fix canned_responses 500: add missing SQL migration
The canned_responses table was registered in autoMigrate() (app.go) but
autoMigrate() is never called on the serve path (Bootstrap -> NewDatabase
-> RunMigrations only). With no SQL migration file, the table never
existed, so POST /api/v1/accounts/:id/canned_responses failed with
'relation does not exist' -> 500.

Add migration 000049 to create the table matching the GORM model
(id, account_id, content, short_code, timestamps) with the account+
short_code partial unique index and deleted_at index.

Also include two related fixes staged in the working tree:
- router.go: register notifications.GET("") alongside GET("/") to avoid
  Gin 301 trailing-slash redirect that the Vite proxy doesn't follow
- notifications/actions.js: stop the infinite loader on fetch error to
  prevent IntersectionObserver re-fire loop
2026-07-08 11:43:34 +08:00
rogee be38051ac5 Fix Reports 500, Settings white screen, SidebarGroup exceptions
ISS-01: Fix reporting_events_rollups table schema mismatch
- The init migration (000001) created columns (dimension, dimension_value,
  metric_name, value, value_in_business_hours, period) that do not match
  the GORM model which expects (date, dimension_type, dimension_id, metric,
  count, sum_value, sum_value_business_hours)
- Add migration 000048 to drop and recreate the table with correct schema
  matching the GORM model and all Go code that references it
- Fixes: GET /api/v2/accounts/:id/reports returning HTTP 500 with
  'column date does not exist (SQLSTATE 42703)'

ISS-02: Fix Settings > General page white screen
- AccountId.vue: add null-safe access for currentAccount.value.id before
  calling toString() — currentAccount can be {} when account data not yet
  loaded in store
- BuildInfo.vue: add null-safe access for globalConfig.value.gitSha and
  globalConfig.value.appVersion; guard copyGitSha with existence check;
  add v-if guard on gitSha span in template

ISS-04: Fix SidebarGroup mounted hook exceptions
- SidebarGroup.vue: Object.keys(child.to.params) throws TypeError when
  child.to.params is undefined; add null-safe fallback Object.keys(child.to?.params ?? {})
- This was the source of the 29 recurring JS exceptions on every Settings
  page navigation

ISS-05: Fix Vue Router root path warning
- Add root route { path: '/', redirect: '/app/login' } to silence
  'No match found for location with path /' warning
2026-07-08 10:02:29 +08:00
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories:
- backend/: Go module root (cmd, internal, pkg, configs, migrations,
  docs/swagger, scripts, tests, go.mod, Makefile, .air.toml)
- deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd
- docs/: project documentation + reports/ (moved from repo root)
- AGENTS.md: new AI coding-agent guide at repo root

Update all references to the new layout:
- Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root)
- docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile,
  env_file ../../.env, volume mounts ../../backend:/app
- deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile
- CI: working-directory: backend for go commands, file deploy/docker/Dockerfile,
  coverage path backend/coverage.out, health_check backend/scripts/
- backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../
- README: architecture tree, quickstart, config paths updated

Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh,
gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to
preserve history. Build, vet, SQLite tests, and docker compose config verified.
2026-07-07 14:44:12 +08:00