feat: bot inbox (#77)

* feat: bot inbox

* feat: unified header

* fix: missing tool_call usage

* feat: add group name in header
This commit is contained in:
Acbox Liu
2026-02-22 01:27:24 +08:00
committed by GitHub
parent 2c6b5e5565
commit c591af14b0
42 changed files with 3367 additions and 260 deletions
+14 -3
View File
@@ -54,13 +54,16 @@ func (s *Service) UpsertBot(ctx context.Context, botID string, req UpsertRequest
}
isPersonalBot := strings.EqualFold(strings.TrimSpace(botRow.Type), "personal")
current := normalizeBotSetting(botRow.MaxContextLoadTime, botRow.MaxContextTokens, botRow.Language, botRow.AllowGuest)
current := normalizeBotSetting(botRow.MaxContextLoadTime, botRow.MaxContextTokens, botRow.MaxInboxItems, botRow.Language, botRow.AllowGuest)
if req.MaxContextLoadTime != nil && *req.MaxContextLoadTime > 0 {
current.MaxContextLoadTime = *req.MaxContextLoadTime
}
if req.MaxContextTokens != nil && *req.MaxContextTokens >= 0 {
current.MaxContextTokens = *req.MaxContextTokens
}
if req.MaxInboxItems != nil && *req.MaxInboxItems >= 0 {
current.MaxInboxItems = *req.MaxInboxItems
}
if strings.TrimSpace(req.Language) != "" {
current.Language = strings.TrimSpace(req.Language)
}
@@ -110,6 +113,7 @@ func (s *Service) UpsertBot(ctx context.Context, botID string, req UpsertRequest
ID: pgID,
MaxContextLoadTime: int32(current.MaxContextLoadTime),
MaxContextTokens: int32(current.MaxContextTokens),
MaxInboxItems: int32(current.MaxInboxItems),
Language: current.Language,
AllowGuest: current.AllowGuest,
ChatModelID: chatModelUUID,
@@ -134,10 +138,11 @@ func (s *Service) Delete(ctx context.Context, botID string) error {
return s.queries.DeleteSettingsByBotID(ctx, pgID)
}
func normalizeBotSetting(maxContextLoadTime int32, maxContextTokens int32, language string, allowGuest bool) Settings {
func normalizeBotSetting(maxContextLoadTime int32, maxContextTokens int32, maxInboxItems int32, language string, allowGuest bool) Settings {
settings := Settings{
MaxContextLoadTime: int(maxContextLoadTime),
MaxContextTokens: int(maxContextTokens),
MaxInboxItems: int(maxInboxItems),
Language: strings.TrimSpace(language),
AllowGuest: allowGuest,
}
@@ -147,6 +152,9 @@ func normalizeBotSetting(maxContextLoadTime int32, maxContextTokens int32, langu
if settings.MaxContextTokens < 0 {
settings.MaxContextTokens = 0
}
if settings.MaxInboxItems <= 0 {
settings.MaxInboxItems = DefaultMaxInboxItems
}
if settings.Language == "" {
settings.Language = DefaultLanguage
}
@@ -157,6 +165,7 @@ func normalizeBotSettingsReadRow(row sqlc.GetSettingsByBotIDRow) Settings {
return normalizeBotSettingsFields(
row.MaxContextLoadTime,
row.MaxContextTokens,
row.MaxInboxItems,
row.Language,
row.AllowGuest,
row.ChatModelID,
@@ -170,6 +179,7 @@ func normalizeBotSettingsWriteRow(row sqlc.UpsertBotSettingsRow) Settings {
return normalizeBotSettingsFields(
row.MaxContextLoadTime,
row.MaxContextTokens,
row.MaxInboxItems,
row.Language,
row.AllowGuest,
row.ChatModelID,
@@ -182,6 +192,7 @@ func normalizeBotSettingsWriteRow(row sqlc.UpsertBotSettingsRow) Settings {
func normalizeBotSettingsFields(
maxContextLoadTime int32,
maxContextTokens int32,
maxInboxItems int32,
language string,
allowGuest bool,
chatModelID pgtype.Text,
@@ -189,7 +200,7 @@ func normalizeBotSettingsFields(
embeddingModelID pgtype.Text,
searchProviderID pgtype.UUID,
) Settings {
settings := normalizeBotSetting(maxContextLoadTime, maxContextTokens, language, allowGuest)
settings := normalizeBotSetting(maxContextLoadTime, maxContextTokens, maxInboxItems, language, allowGuest)
settings.ChatModelID = strings.TrimSpace(chatModelID.String)
settings.MemoryModelID = strings.TrimSpace(memoryModelID.String)
settings.EmbeddingModelID = strings.TrimSpace(embeddingModelID.String)