Files
tutti/services/tuttid/service/agent/source_session_deletion.go
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

53 lines
1.9 KiB
Go

package agent
import (
"context"
"errors"
"strings"
agenthost "github.com/tutti-os/tutti/packages/agent/host"
)
func (s *Service) Delete(ctx context.Context, workspaceID string, agentSessionID string) (DeleteSessionResult, error) {
workspaceID = strings.TrimSpace(workspaceID)
agentSessionID = strings.TrimSpace(agentSessionID)
if workspaceID == "" || agentSessionID == "" {
return DeleteSessionResult{}, ErrInvalidArgument
}
// Host owns live close + canonical removal; do not pre-close or the
// live-only delete-before-report conformance path cannot observe the
// session.
result, err := s.ApplicationHost().DeleteSession(ctx, agenthost.SessionRef{
WorkspaceID: workspaceID, AgentSessionID: agentSessionID,
})
if err != nil {
if errors.Is(err, agenthost.ErrSessionNotFound) || errors.Is(err, ErrSessionNotFound) {
if tuttiErr := s.deleteTuttiModeActivationSessionState(ctx, workspaceID, agentSessionID); tuttiErr != nil {
return DeleteSessionResult{}, tuttiErr
}
s.forgetProviderRuntimeSessionCredentials(workspaceID, agentSessionID)
}
return DeleteSessionResult{}, err
}
s.forgetProviderRuntimeSessionCredentials(workspaceID, agentSessionID)
return DeleteSessionResult{Removed: result.Deleted, CleanupFailed: result.CleanupFailed}, nil
}
func (s *Service) Clear(ctx context.Context, workspaceID string) (ClearSessionsResult, error) {
workspaceID = strings.TrimSpace(workspaceID)
if workspaceID == "" {
return ClearSessionsResult{}, ErrInvalidArgument
}
result, err := s.ApplicationHost().ClearSessions(ctx, workspaceID)
if err != nil {
return ClearSessionsResult{}, err
}
s.forgetProviderRuntimeSessionCredentials(workspaceID, result.RemovedSessionIDs...)
return ClearSessionsResult{
RemovedMessages: result.RemovedMessages,
RemovedSessions: result.RemovedSessions,
RemovedSessionIDs: result.RemovedSessionIDs,
CleanupFailedSessionIDs: result.CleanupFailedIDs,
}, nil
}