Changeset 0.29.0 (#195)
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.gobha.me/xcaliber/chat-switchboard/database"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/models"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/providers"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/roles"
|
||||
@@ -173,16 +172,22 @@ Write the summary in a way that would allow the conversation to continue natural
|
||||
metaJSON, _ := json.Marshal(metadata)
|
||||
siblingIdx := treepath.NextSiblingIndex(req.ChannelID, &lastMessageID)
|
||||
|
||||
var summaryMsgID string
|
||||
err = database.DB.QueryRow(`
|
||||
INSERT INTO messages (channel_id, parent_id, role, content, model, metadata, sibling_index, participant_type)
|
||||
VALUES ($1, $2, 'assistant', $3, $4, $5, $6, 'system')
|
||||
RETURNING id
|
||||
`, req.ChannelID, lastMessageID, result.Content, result.Model, string(metaJSON), siblingIdx).Scan(&summaryMsgID)
|
||||
if err != nil {
|
||||
summaryMsg := &models.Message{
|
||||
ChannelID: req.ChannelID,
|
||||
ParentID: &lastMessageID,
|
||||
Role: "assistant",
|
||||
Content: result.Content,
|
||||
Model: result.Model,
|
||||
Metadata: models.JSONMap{},
|
||||
SiblingIndex: siblingIdx,
|
||||
ParticipantType: "system",
|
||||
}
|
||||
_ = json.Unmarshal(metaJSON, &summaryMsg.Metadata)
|
||||
if err := s.stores.Messages.Create(ctx, summaryMsg); err != nil {
|
||||
log.Printf("⚠ Failed to persist summary for channel %s: %v", req.ChannelID, err)
|
||||
return nil, fmt.Errorf("failed to save summary: %w", err)
|
||||
}
|
||||
summaryMsgID := summaryMsg.ID
|
||||
|
||||
// Update cursor to point to the summary node
|
||||
if err := treepath.UpdateCursor(req.ChannelID, req.UserID, summaryMsgID); err != nil {
|
||||
@@ -268,11 +273,8 @@ func (s *Service) CheckRateLimit(ctx context.Context, userID string) error {
|
||||
|
||||
// GetUserTeamID returns the user's first team ID (for role resolution).
|
||||
func (s *Service) GetUserTeamID(ctx context.Context, userID string) *string {
|
||||
var teamID string
|
||||
err := database.DB.QueryRow(`
|
||||
SELECT team_id FROM team_members WHERE user_id = $1 LIMIT 1
|
||||
`, userID).Scan(&teamID)
|
||||
if err != nil || teamID == "" {
|
||||
teamID, _ := s.stores.Teams.GetFirstTeamIDForUser(ctx, userID)
|
||||
if teamID == "" {
|
||||
return nil
|
||||
}
|
||||
return &teamID
|
||||
|
||||
Reference in New Issue
Block a user