ultisuite-backend/internal/apitokens/chat_session.go
R3D347HR4Y 1d063237b9
Some checks are pending
CI / Go tests (push) Waiting to run
CI / Integration tests (push) Waiting to run
CI / DB migrations (push) Waiting to run
feat(transcription): integrate Faster Whisper for Jitsi transcriptions
- Added support for Faster Whisper transcription via Jigasi and Skynet.
- Updated .env.example to include new environment variables for transcription settings.
- Enhanced Jitsi Docker Compose configuration to include Skynet and Jigasi services.
- Introduced new API endpoints for managing organizational folders in the drive service.
- Updated Nextcloud initialization script to enable external file mounting.
- Improved error handling and response structures in the drive API.
- Added new properties for organization settings related to transcription and agenda management.
2026-06-12 19:10:18 +02:00

89 lines
2.7 KiB
Go

package apitokens
import (
"context"
"fmt"
"strings"
"time"
"github.com/jackc/pgx/v5/pgxpool"
)
type ChatSessionPreset string
const (
ChatSessionMail ChatSessionPreset = "mail"
ChatSessionDrive ChatSessionPreset = "drive"
ChatSessionContacts ChatSessionPreset = "contacts"
ChatSessionDocs ChatSessionPreset = "docs"
ChatSessionStandalone ChatSessionPreset = "standalone"
)
type ChatSessionInput struct {
Preset ChatSessionPreset
DrivePath string
AllowWrite bool
TTL time.Duration
}
func CreateChatSession(ctx context.Context, db *pgxpool.Pool, externalID, email string, in ChatSessionInput) (CreatedToken, error) {
if in.TTL <= 0 {
in.TTL = 8 * time.Hour
}
expiresAt := time.Now().UTC().Add(in.TTL)
perms, mailScope, driveScope := chatSessionGrants(in)
name := fmt.Sprintf("UltiAI session %s", time.Now().UTC().Format("2006-01-02 15:04"))
return Create(ctx, db, externalID, name, perms, mailScope, driveScope, AgendaScope{AllCalendars: true}, &expiresAt)
}
func chatSessionGrants(in ChatSessionInput) ([]PermissionGrant, MailScope, DriveScope) {
mailScope := MailScope{AllAccounts: true}
driveScope := DriveScope{AllFolders: true}
if strings.TrimSpace(in.DrivePath) != "" {
driveScope = DriveScope{
AllFolders: false,
FolderPaths: []string{in.DrivePath},
}
}
switch in.Preset {
case ChatSessionMail:
return []PermissionGrant{
{Resource: "mail.messages", Read: true},
{Resource: "mail.search", Read: true},
{Resource: "contacts.read", Read: true},
{Resource: "automation.chat", Read: true},
}, mailScope, driveScope
case ChatSessionDrive:
return []PermissionGrant{
{Resource: "drive.files", Read: true, Write: in.AllowWrite},
{Resource: "automation.chat", Read: true},
}, mailScope, driveScope
case ChatSessionContacts:
return []PermissionGrant{
{Resource: "contacts.read", Read: true},
{Resource: "contacts.search", Read: true},
{Resource: "mail.search", Read: true},
{Resource: "automation.chat", Read: true},
}, mailScope, driveScope
case ChatSessionDocs:
return []PermissionGrant{
{Resource: "drive.files", Read: true, Write: in.AllowWrite},
{Resource: "drive.download", Read: true},
{Resource: "automation.chat", Read: true},
}, mailScope, driveScope
default:
return []PermissionGrant{
{Resource: "mail.messages", Read: true},
{Resource: "mail.search", Read: true},
{Resource: "mail.send", Write: true},
{Resource: "mail.labels", Read: true, Write: true},
{Resource: "drive.files", Read: true, Write: true},
{Resource: "contacts.read", Read: true},
{Resource: "contacts.search", Read: true},
{Resource: "automation.search", Read: true},
{Resource: "automation.chat", Read: true},
}, mailScope, driveScope
}
}