User authorized lifting CURRENT FAV whole-branch merge protection on 2026-09-23. Keep FAV_DEGRADED_READ/FAV_PUBLISHER_ENABLED default false. Drop duplicate goose 00034 (local_dev already has 00036). Preserve agentx workspace admin routes and pin-export wiring.
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package freedoc
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"sync"
|
|
|
|
"chat-agent-system/internal/ctxmgr"
|
|
"chat-agent-system/internal/docrevision"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
type Service struct {
|
|
pool *pgxpool.Pool
|
|
ctxMgr *ctxmgr.ContextManager
|
|
docRev *docrevision.Service
|
|
|
|
mu sync.RWMutex
|
|
memDocs map[string]*FreeformDocument
|
|
memVersions map[string][]*FreeformDocumentVersion
|
|
memAudit []map[string]any
|
|
// memClientKeys mirrors PG uq_freeform_owner_client_key (owner|client_key → doc_id)
|
|
memClientKeys map[string]string
|
|
|
|
OnFinalArtifact func(ctx context.Context, projectID int64, docID, eventID string, snapshotID int64, payload []byte)
|
|
}
|
|
|
|
func NewService(pool *pgxpool.Pool, ctxMgr *ctxmgr.ContextManager) *Service {
|
|
return &Service{
|
|
pool: pool,
|
|
ctxMgr: ctxMgr,
|
|
memDocs: make(map[string]*FreeformDocument),
|
|
memVersions: make(map[string][]*FreeformDocumentVersion),
|
|
memAudit: make([]map[string]any, 0),
|
|
memClientKeys: make(map[string]string),
|
|
}
|
|
}
|
|
|
|
// SetDocRevision attaches the shared revision ledger (Wave 6 freeform compatibility).
|
|
func (s *Service) SetDocRevision(rev *docrevision.Service) {
|
|
if s != nil {
|
|
s.docRev = rev
|
|
}
|
|
}
|
|
|
|
func computeSHA256(text string) string {
|
|
sum := sha256.Sum256([]byte(text))
|
|
return hex.EncodeToString(sum[:])
|
|
}
|