session

package
v0.0.80 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManagerSessionKey = "sessionManager"
)

Variables

This section is empty.

Functions

func UISession

func UISession(next http.Handler, sessionStore *Manager, apiHandler http.Handler) http.Handler

Types

type ConfigWrapper

type ConfigWrapper types.Config

func (*ConfigWrapper) Scan

func (c *ConfigWrapper) Scan(value any) error

func (ConfigWrapper) Value

func (c ConfigWrapper) Value() (driver.Value, error)

type Env

type Env map[string]string

func (*Env) Scan

func (e *Env) Scan(value any) error

func (Env) Value

func (e Env) Value() (driver.Value, error)

type Manager

type Manager struct {
	DB *Store
	// contains filtered or unexported fields
}

func NewManager

func NewManager(store *Store) *Manager

func (*Manager) Acquire

func (m *Manager) Acquire(ctx context.Context, server mcp.MessageHandler, id string) (ret *mcp.ServerSession, found bool, retErr error)

func (*Manager) ExtractID

func (m *Manager) ExtractID(req *http.Request) string

func (*Manager) LoadAndDelete

func (m *Manager) LoadAndDelete(ctx context.Context, server mcp.MessageHandler, id string) (*mcp.ServerSession, bool, error)

func (*Manager) Release

func (m *Manager) Release(session *mcp.ServerSession)

func (*Manager) Store

func (m *Manager) Store(ctx context.Context, id string, session *mcp.ServerSession) error

type ScheduledTask

type ScheduledTask struct {
	gorm.Model
	TaskURI   string     `json:"taskURI" gorm:"uniqueIndex;not null"`
	Name      string     `json:"name"`
	Prompt    string     `json:"prompt" gorm:"type:text"`
	Schedule  string     `json:"schedule"`
	Timezone  string     `json:"timezone"`
	Enabled   bool       `json:"enabled" gorm:"not null"`
	ExpiresAt *time.Time `json:"expiresAt,omitempty"`
	LastRunAt *time.Time `json:"lastRunAt,omitempty"`
	NextRunAt *time.Time `json:"nextRunAt,omitempty" gorm:"index"`
}

ScheduledTask is the persisted definition for a scheduled chat run.

type Session

type Session struct {
	gorm.Model
	Type        string        `json:"type,omitempty"`
	SessionID   string        `json:"sessionId" gorm:"uniqueIndex;not null"`
	Description string        `json:"description,omitempty"`
	AccountID   string        `json:"accountId,omitempty"`
	TaskURI     string        `json:"taskURI,omitempty" gorm:"index"`
	State       State         `json:"state" gorm:"type:json"`
	Config      ConfigWrapper `json:"config,omitempty" gorm:"type:json"`
	Cwd         string        `json:"cwd,omitempty"`
}

type State

type State mcp.SessionState

func (*State) Scan

func (m *State) Scan(value any) error

func (State) Value

func (m State) Value() (driver.Value, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(db *gorm.DB) *Store

func NewStoreFromDSN

func NewStoreFromDSN(dsn string) (store *Store, err error)

func (*Store) AddWorkflowRun

func (s *Store) AddWorkflowRun(ctx context.Context, sessionID, workflowURI string) error

AddWorkflowRun records a workflow run for a session and ignores duplicates.

func (*Store) Create

func (s *Store) Create(ctx context.Context, session *Session) error

func (*Store) CreateScheduledTask

func (s *Store) CreateScheduledTask(ctx context.Context, task *ScheduledTask) error

CreateScheduledTask inserts a new scheduled task record.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

func (*Store) DeleteScheduledTask

func (s *Store) DeleteScheduledTask(ctx context.Context, taskURI string) error

DeleteScheduledTask deletes a scheduled task by its task URI.

func (*Store) DeleteTokenConfig

func (s *Store) DeleteTokenConfig(ctx context.Context, url string) error

func (*Store) FindByAccount

func (s *Store) FindByAccount(ctx context.Context, sessionType, accountID string) ([]Session, error)

func (*Store) FindByPrefix

func (s *Store) FindByPrefix(ctx context.Context, sessionIDPrefix string) ([]Session, error)

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*Session, error)

func (*Store) GetByIDByAccountID

func (s *Store) GetByIDByAccountID(ctx context.Context, id, accountID string) (*Session, error)

func (*Store) GetScheduledTask

func (s *Store) GetScheduledTask(ctx context.Context, taskURI string) (*ScheduledTask, error)

GetScheduledTask returns a scheduled task by its task URI.

func (*Store) GetTokenConfig

func (s *Store) GetTokenConfig(ctx context.Context, url string) (*oauth2.Config, *oauth2.Token, error)

func (*Store) List

func (s *Store) List(ctx context.Context) ([]Session, error)

func (*Store) ListScheduledTasks

func (s *Store) ListScheduledTasks(ctx context.Context) ([]ScheduledTask, error)

ListScheduledTasks returns all scheduled tasks ordered newest-first.

func (*Store) ListWorkflowURIs

func (s *Store) ListWorkflowURIs(ctx context.Context, sessionIDs ...string) (map[string][]string, error)

ListWorkflowURIs returns the URIs of the workflows that have been run in each of the given sessions.

func (*Store) NextScheduledTaskURI

func (s *Store) NextScheduledTaskURI(ctx context.Context, name string) (string, error)

NextScheduledTaskURI builds the next stable task URI for the given name.

func (*Store) RecordScheduledTaskRun

func (s *Store) RecordScheduledTaskRun(ctx context.Context, taskURI string, lastRunAt time.Time, nextRunAt *time.Time) error

RecordScheduledTaskRun records when a scheduled task last ran and when it will next run.

func (*Store) SetTokenConfig

func (s *Store) SetTokenConfig(ctx context.Context, url string, oauth2Config *oauth2.Config, oauth2token *oauth2.Token) error

func (*Store) Update

func (s *Store) Update(ctx context.Context, session *Session) error

func (*Store) UpdateScheduledTask

func (s *Store) UpdateScheduledTask(ctx context.Context, task *ScheduledTask) error

UpdateScheduledTask persists definition changes to an existing scheduled task. Only writes configuration columns — never touches LastRunAt.

type Token

type Token struct {
	gorm.Model
	AccountID string `json:"accountID,omitempty"`
	URL       string `json:"url,omitempty"`
	Data      string `json:"data,omitempty"`
}

type WorkflowRun

type WorkflowRun struct {
	SessionID   string `json:"sessionId" gorm:"primaryKey;not null"`
	WorkflowURI string `json:"workflowURI" gorm:"primaryKey;not null"`
}

WorkflowRun records that a workflow was executed within a session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL