feat: harden support, localize knowledge and add operator availability [skip ci]

Source-only publication of reviewed commit 64e96a7f423673dc29ad56485be9fc79bce8af1c.

Passed in isolation: focused frontend/backend tests, race checks, TypeScript typecheck, lint, Go compilation, Flowgram build, and deterministic SDK build/tests.

Not accepted as a production release: Next.js export/native assembly remains blocked by environment memory limits; browser interaction and MySQL staging acceptance remain unverified. No production server, database/schema, runtime configuration, deployment, release tag, or workflow execution was performed.

Expected source tree: 0a4a7528e9.
This commit is contained in:
2026-10-16 15:21:42 +00:00
parent 299ea50fb5
commit 2f7a491666
176 changed files with 11869 additions and 2716 deletions

View File

@@ -1,3 +1,6 @@
// Modified in AgentDeskNext: authenticated support availability and calendars.
// Modified in the independent hardening fork; see docs/hardening.
package models
import (
@@ -45,6 +48,8 @@ var Models = []any{
&AgentProfile{},
&AgentTeam{},
&AgentTeamSchedule{},
&SupportCalendar{},
&AgentPresenceLease{},
&AIConfig{},
&KnowledgeBase{},
&KnowledgeDirectory{},
@@ -250,6 +255,10 @@ type Customer struct {
// CustomerIdentity 客户第三方身份映射表。
type CustomerIdentity struct {
// Empty scope is legacy/internal integration data; public sessions never fall back to it.
IdentityScope string `gorm:"type:varchar(80);not null;default:'';index:idx_customer_identity_scope"`
// Nullable for legacy rows; all new public scoped identities claim a unique digest.
ScopedKey *string `gorm:"type:varchar(64);uniqueIndex:uk_customer_scoped_key"`
ID int64 `gorm:"primaryKey;autoIncrement"`
CustomerID int64 `gorm:"type:bigint;not null;uniqueIndex:uk_customer_external"` // 为所属客户ID。
ExternalSource enums.ExternalSource `gorm:"type:varchar(30);uniqueIndex:uk_customer_external"` // 为外部身份来源
@@ -777,21 +786,25 @@ type TicketProgress struct {
// AgentProfile 客服档案。
type AgentProfile struct {
ID int64 `gorm:"primaryKey;autoIncrement"` // ID 为客服档案主键。
UserID int64 `gorm:"type:bigint;not null;uniqueIndex"` // UserID 关联后台用户,一名用户只允许一份客服档案。
TeamID int64 `gorm:"type:bigint;not null;default:0;index"` // TeamID 为客服所属客服组。
AgentCode string `gorm:"type:varchar(64);not null;default:'';uniqueIndex"` // AgentCode 为客服工号,用于业务侧识别客服。
DisplayName string `gorm:"type:varchar(100);not null;default:'';index"` // DisplayName 为客服展示名,可区别于后台昵称。
Avatar string `gorm:"type:varchar(1024);not null;default:''"` // Avatar 为客服头像 URL。
ServiceStatus enums.ServiceStatus `gorm:"type:int;not null;default:0;index"` // ServiceStatus 表示客服服务状态:0空闲 1忙碌。
MaxConcurrentCount int `gorm:"type:int;not null;default:0"` // MaxConcurrentCount 表示客服最大并发接待数。
PriorityLevel int `gorm:"type:int;not null;default:0;index"` // PriorityLevel 表示自动分配优先级,值越大越优先。
AutoAssignEnabled bool `gorm:"not null;default:true;index"` // AutoAssignEnabled 表示是否参与自动分配。
ReceiveOfflineMessage bool `gorm:"not null;default:false"` // ReceiveOfflineMessage 表示离线时是否仍接收离线消息或转接消息。
LastOnlineAt *time.Time `gorm:"index"` // LastOnlineAt 记录最近一次在线时间。
LastStatusAt *time.Time `gorm:"index"` // LastStatusAt 记录最近一次状态变更时间。
Status enums.Status `gorm:"type:int;not null;default:0;index"` // Status 表示客服档案状态
Remark string `gorm:"type:text"` // Remark 记录客服备注信息。
ID int64 `gorm:"primaryKey;autoIncrement"` // ID 为客服档案主键。
UserID int64 `gorm:"type:bigint;not null;uniqueIndex"` // UserID 关联后台用户,一名用户只允许一份客服档案。
TeamID int64 `gorm:"type:bigint;not null;default:0;index"` // TeamID 为客服所属客服组。
AgentCode string `gorm:"type:varchar(64);not null;default:'';uniqueIndex"` // AgentCode 为客服工号,用于业务侧识别客服。
DisplayName string `gorm:"type:varchar(100);not null;default:'';index"` // DisplayName 为客服展示名,可区别于后台昵称。
Avatar string `gorm:"type:varchar(1024);not null;default:''"` // Avatar 为客服头像 URL。
AvailabilityReturnStatus enums.ServiceStatus `gorm:"not null;default:0"`
AbsenceStartAt *time.Time `gorm:"index"`
AbsenceEndAt *time.Time `gorm:"index"`
AssignmentVersion int64 `gorm:"not null;default:0"`
ServiceStatus enums.ServiceStatus `gorm:"type:int;not null;default:0;index"` // ServiceStatus stores working state; effective vacation state is evaluated from its dated interval.
MaxConcurrentCount int `gorm:"type:int;not null;default:0"` // MaxConcurrentCount limits active conversations; zero is unlimited.
PriorityLevel int `gorm:"type:int;not null;default:0;index"` // PriorityLevel 表示自动分配优先级,值越大越优先。
AutoAssignEnabled bool `gorm:"not null;default:true;index"` // AutoAssignEnabled 表示是否参与自动分配。
ReceiveOfflineMessage bool `gorm:"not null;default:false"` // ReceiveOfflineMessage is deprecated compatibility data; it never bypasses live eligibility.
LastOnlineAt *time.Time `gorm:"index"` // LastOnlineAt is historical metadata, not the source of live platform presence.
LastStatusAt *time.Time `gorm:"index"` // LastStatusAt 记录最近一次状态变更时间。
Status enums.Status `gorm:"type:int;not null;default:0;index"` // Status 表示客服档案状态
Remark string `gorm:"type:text"` // Remark 记录客服备注信息。
AuditFields
}

View File

@@ -0,0 +1,24 @@
package models
import "time"
// SupportCalendar is opt-in. Absence of a team row preserves dated schedules.
// TeamID zero stores the deployment-wide timezone, not another organization.
type SupportCalendar struct {
ID int64 `gorm:"primaryKey;autoIncrement"`
TeamID int64 `gorm:"not null;uniqueIndex"`
Mode string `gorm:"type:varchar(20);not null;default:'legacy'"`
Timezone string `gorm:"type:varchar(100);not null;default:''"`
WeeklyJSON string `gorm:"type:text;not null"`
ExceptionsJSON string `gorm:"type:text;not null"`
UpdatedAt time.Time
}
// AgentPresenceLease contains no bearer credential or client address. Multiple
// independent connections may lease presence for the same authenticated user.
type AgentPresenceLease struct {
ID string `gorm:"type:varchar(64);primaryKey"`
UserID int64 `gorm:"not null;index"`
LoginSessionID int64 `gorm:"not null;index"`
ExpiresAt time.Time `gorm:"not null;index"`
}