usecase

package
v1.0.28 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BedrockService added in v1.0.10

type BedrockService interface {
	// GetCurrentUsage retrieves the current Bedrock usage statistics
	// for all configured regions
	GetCurrentUsage() (*entity.BedrockUsage, error)

	// GetUsageForRegion retrieves usage statistics for a specific region
	GetUsageForRegion(region string) (*entity.BedrockUsage, error)

	// GetDailyUsage retrieves aggregated usage for a specific date
	// Uses JST timezone for date boundaries
	GetDailyUsage(date time.Time) (*entity.BedrockUsage, error)

	// GetCurrentMonthUsage retrieves usage for the current month
	GetCurrentMonthUsage() (*entity.BedrockUsage, error)

	// IsEnabled checks if Bedrock tracking is enabled in configuration
	IsEnabled() bool

	// CheckConnection verifies AWS credentials and CloudWatch access
	CheckConnection() error

	// GetConfiguredRegions returns the list of configured regions
	GetConfiguredRegions() []string

	// GetAvailableRegions returns regions with Bedrock activity
	GetAvailableRegions() ([]string, error)
}

BedrockService defines the interface for Bedrock-related operations

type CSVExportOptions added in v1.0.12

type CSVExportOptions struct {
	OutputPath  string
	StartTime   *time.Time
	EndTime     *time.Time
	MetricTypes []string // claude_code, cursor, bedrock, vertex_ai
}

CSVExportOptions represents options for CSV export

type CSVExportService added in v1.0.12

type CSVExportService interface {
	// Export exports metrics data to CSV file
	Export(options CSVExportOptions) error
}

CSVExportService defines the interface for CSV export use cases

type CcDataEntry

type CcDataEntry struct {
	ID                  string
	Timestamp           time.Time
	Date                string
	SessionID           string
	ProjectPath         string
	Model               string
	InputTokens         int
	OutputTokens        int
	CacheCreationTokens int
	CacheReadTokens     int
	TotalTokens         int
	Cost                float64
	Currency            string
	Version             string
	MessageID           string
	RequestID           string
}

CcDataEntry represents a single cc entry

type CcDataFilter

type CcDataFilter struct {
	StartDate   *time.Time
	EndDate     *time.Time
	ProjectPath string
	Model       string
	SessionID   string
	Limit       int
	Offset      int
}

CcDataFilter defines filters for loading cc data

type CcDataResult

type CcDataResult struct {
	Entries    []CcDataEntry
	TotalCount int
	HasMore    bool
}

CcDataResult contains loaded cc data

type CcService

type CcService interface {
	// CalculateDailyTokens calculates total token count for a specific date
	CalculateDailyTokens(date time.Time) (int, error)

	// CalculateTodayTokens calculates total token count for today
	CalculateTodayTokens() (int, error)

	// CalculateTokenStats calculates aggregated token statistics
	CalculateTokenStats(filter TokenStatsFilter) (*TokenStatsResult, error)

	// CalculateCostBreakdown calculates cost breakdown by various dimensions
	CalculateCostBreakdown(filter CostBreakdownFilter) (*CostBreakdownResult, error)

	// CalculateModelBreakdown calculates cc breakdown by model
	CalculateModelBreakdown(filter ModelBreakdownFilter) (*ModelBreakdownResult, error)

	// CalculateDateBreakdown calculates cc breakdown by date
	CalculateDateBreakdown(filter DateBreakdownFilter) (*DateBreakdownResult, error)

	// LoadCcData loads cc data with optional filters
	LoadCcData(filter CcDataFilter) (*CcDataResult, error)

	// GetCcSummary returns a summary of cc statistics
	GetCcSummary(filter CcSummaryFilter) (*CcSummaryResult, error)

	// EstimateMonthlyCost estimates monthly cost based on recent cc
	EstimateMonthlyCost(daysToAverage int) (*CostEstimateResult, error)

	// GetAvailableProjects returns list of available projects
	GetAvailableProjects() ([]string, error)

	// GetAvailableModels returns list of available models
	GetAvailableModels() ([]string, error)

	// GetDateRange returns the date range of available data
	GetDateRange() (start, end time.Time, err error)

	// CalculateDailyTokensInUserTimezone calculates total token count for a specific date in user's timezone
	CalculateDailyTokensInUserTimezone(date time.Time) (int, error)

	// CalculateTodayTokensInUserTimezone calculates total token count for today in user's timezone
	CalculateTodayTokensInUserTimezone() (int, error)

	// GetDateRangeInUserTimezone returns the date range of available data in user's timezone
	GetDateRangeInUserTimezone() (start, end time.Time, err error)
}

CcService defines the interface for cc-related use cases

type CcSummaryFilter

type CcSummaryFilter struct {
	StartDate   *time.Time
	EndDate     *time.Time
	ProjectPath string
	Model       string
}

CcSummaryFilter defines filters for cc summary

type CcSummaryResult

type CcSummaryResult struct {
	TotalTokens        int
	TotalCost          float64
	Currency           string
	EntryCount         int
	UniqueProjects     int
	UniqueModels       int
	UniqueSessions     int
	DateRange          DateRange
	AverageDailyTokens int
	AverageDailyCost   float64
	MostUsedModel      string
	MostActiveProject  string
	TokenDistribution  TokenDistribution
}

CcSummaryResult contains cc summary information

type ConfigMigrationService added in v1.0.12

type ConfigMigrationService interface {
	// NeedsMigration は設定がマイグレーションを必要とするかチェックする
	NeedsMigration(config *config.AppConfig) bool

	// Migrate はレガシー形式から現在の形式への移行を実行する
	Migrate(config *config.AppConfig) (*config.AppConfig, error)

	// GetCurrentVersion は現在の設定バージョンを返す
	GetCurrentVersion() int
}

ConfigMigrationService は設定マイグレーションサービスのインターフェース

type ConfigService

type ConfigService interface {
	// GetConfig は現在の設定を取得する
	GetConfig() *config.AppConfig

	// UpdateConfig は設定を更新する
	UpdateConfig(newConfig *config.AppConfig) error

	// GetConfigWithSources は設定とそのソース情報を取得する
	GetConfigWithSources() (*config.AppConfig, config.ConfigSourceMap)

	// SaveConfig は現在の設定をファイルに保存する
	SaveConfig() error

	// ReloadConfig は設定を再読み込みする
	ReloadConfig() error

	// GetConfigPath は設定ファイルのパスを返す
	GetConfigPath() string

	// CreateDefaultConfig はデフォルト設定ファイルを作成する
	CreateDefaultConfig() error

	// ExportConfig は現在の設定をエクスポート用に整形する(パスワードなどをマスク)
	ExportConfig() map[string]interface{}

	// EnsureConfigExists は設定ファイルが存在することを確認し、存在しない場合はテンプレートを作成する
	EnsureConfigExists() error

	// CreateTemplateConfig はテンプレート設定ファイルを作成する
	CreateTemplateConfig() error

	// LoadConfigWithFallback はエラー耐性のある設定読み込みを行う
	LoadConfigWithFallback() (*config.AppConfig, error)

	// LoadConfigWithMigration はマイグレーション対応の設定読み込みを行う
	LoadConfigWithMigration() (*config.AppConfig, error)
}

ConfigService は設定管理のサービスインターフェース

type CostBreakdownFilter

type CostBreakdownFilter struct {
	StartDate   *time.Time
	EndDate     *time.Time
	ProjectPath string
	GroupBy     GroupByType
}

CostBreakdownFilter defines filters for cost breakdown calculation

type CostBreakdownItem

type CostBreakdownItem struct {
	Key                 string // Model name, date, project path, or session ID
	InputTokens         int
	OutputTokens        int
	CacheCreationTokens int
	CacheReadTokens     int
	TotalTokens         int
	Cost                float64
	Currency            string
	EntryCount          int
	Percentage          float64 // Percentage of total cost
}

CostBreakdownItem represents a single item in cost breakdown

type CostBreakdownResult

type CostBreakdownResult struct {
	Breakdowns []CostBreakdownItem
	Total      TokenStatsResult
}

CostBreakdownResult contains the result of cost breakdown calculation

type CostEstimateResult

type CostEstimateResult struct {
	EstimatedMonthlyCost float64
	Currency             string
	BasedOnDays          int
	AverageDailyCost     float64
	Confidence           float64 // 0-1, based on data availability
}

CostEstimateResult contains monthly cost estimate

type CursorService

type CursorService interface {
	// GetCurrentUsage retrieves the current Cursor usage statistics
	GetCurrentUsage() (*entity.CursorUsage, error)

	// GetUsageLimit retrieves the current usage limit settings
	GetUsageLimit() (*repository.UsageLimitInfo, error)

	// IsUsageBasedPricingEnabled checks if usage-based pricing is enabled
	IsUsageBasedPricingEnabled() (bool, error)

	// GetAggregatedTokenUsage retrieves aggregated token usage from JST 00:00 to current time
	GetAggregatedTokenUsage() (int64, error)
}

CursorService defines the interface for Cursor-related operations

type DateBreakdownFilter

type DateBreakdownFilter struct {
	StartDate   *time.Time
	EndDate     *time.Time
	ProjectPath string
	Model       string
}

DateBreakdownFilter defines filters for date breakdown

type DateBreakdownItem

type DateBreakdownItem struct {
	Date                string // YYYY-MM-DD format
	InputTokens         int
	OutputTokens        int
	CacheCreationTokens int
	CacheReadTokens     int
	TotalTokens         int
	Cost                float64
	Currency            string
	EntryCount          int
}

DateBreakdownItem represents cc for a single date

type DateBreakdownResult

type DateBreakdownResult struct {
	Dates []DateBreakdownItem
	Total TokenStatsResult
}

DateBreakdownResult contains the result of date breakdown

type DateRange

type DateRange struct {
	Start time.Time
	End   time.Time
	Days  int
}

DateRange represents a date range

type GroupByType

type GroupByType string

GroupByType defines how to group the breakdown

const (
	GroupByModel   GroupByType = "model"
	GroupByDate    GroupByType = "date"
	GroupByProject GroupByType = "project"
	GroupBySession GroupByType = "session"
)

type MetricsDataCollector added in v1.0.12

type MetricsDataCollector interface {
	// Collect collects metrics data from all sources
	Collect(startTime, endTime time.Time, metricTypes []string) ([]*entity.MetricRecord, error)
}

MetricsDataCollector defines the interface for collecting metrics data

type MetricsService

type MetricsService interface {
	// StartPeriodicMetrics starts the periodic metrics collection
	StartPeriodicMetrics() error

	// StopPeriodicMetrics stops the periodic metrics collection
	StopPeriodicMetrics() error

	// SendCurrentMetrics sends the current metrics immediately
	SendCurrentMetrics() error
}

MetricsService defines the interface for metrics collection and reporting

type MetricsServiceError

type MetricsServiceError struct {
	Code    string
	Message string
	Details map[string]interface{}
}

MetricsServiceError represents an error from metrics service operations

func NewMetricsServiceError

func NewMetricsServiceError(code, message string) *MetricsServiceError

NewMetricsServiceError creates a new metrics service error

func (*MetricsServiceError) Error

func (e *MetricsServiceError) Error() string

func (*MetricsServiceError) WithDetail

func (e *MetricsServiceError) WithDetail(key string, value interface{}) *MetricsServiceError

WithDetail adds a detail to the error

type ModelBreakdownFilter

type ModelBreakdownFilter struct {
	StartDate   *time.Time
	EndDate     *time.Time
	ProjectPath string
}

ModelBreakdownFilter defines filters for model breakdown

type ModelBreakdownItem

type ModelBreakdownItem struct {
	ModelName           string
	InputTokens         int
	OutputTokens        int
	CacheCreationTokens int
	CacheReadTokens     int
	TotalTokens         int
	Cost                float64
	Currency            string
	EntryCount          int
	TokenPercentage     float64
	CostPercentage      float64
}

ModelBreakdownItem represents cc for a single model

type ModelBreakdownResult

type ModelBreakdownResult struct {
	Models []ModelBreakdownItem
	Total  TokenStatsResult
}

ModelBreakdownResult contains the result of model breakdown

type RestartManager

type RestartManager interface {
	// RequestRestart はアプリケーションの再起動をリクエストする
	RequestRestart() error

	// ScheduleRestart は指定された秒数後に再起動をスケジュールする
	ScheduleRestart(delaySec int) error

	// CancelRestart はスケジュールされた再起動をキャンセルする
	CancelRestart() error

	// IsRestartPending は再起動が保留中かどうかを返す
	IsRestartPending() bool

	// GetRestartReason は再起動の理由を返す
	GetRestartReason() string

	// SetRestartReason は再起動の理由を設定する
	SetRestartReason(reason string)
}

RestartManager はアプリケーションの再起動を管理するインターフェース

type StatusInfo

type StatusInfo struct {
	// IsRunning indicates whether the daemon is currently running
	IsRunning bool

	// LastMetricsSentAt is the timestamp of the last successful metrics send
	LastMetricsSentAt *time.Time

	// NextMetricsSendAt is the timestamp when the next metrics send is scheduled
	NextMetricsSendAt *time.Time

	// TodayTokenCount is the total token count for today
	TodayTokenCount int64

	// LastError is the last error that occurred (if any)
	LastError error

	// LastErrorAt is the timestamp of the last error
	LastErrorAt *time.Time

	// DaemonStartedAt is the timestamp when the daemon was started
	DaemonStartedAt *time.Time
}

StatusInfo represents the current status of the application

type StatusService

type StatusService interface {
	// GetStatus returns the current status information
	GetStatus() (*StatusInfo, error)

	// UpdateLastMetricsSent updates the last metrics sent timestamp
	UpdateLastMetricsSent(sentAt time.Time) error

	// UpdateNextMetricsSend updates the next metrics send timestamp
	UpdateNextMetricsSend(nextAt time.Time) error

	// UpdateTodayTokenCount updates today's token count
	UpdateTodayTokenCount(count int64) error

	// RecordError records an error that occurred
	RecordError(err error) error

	// ClearError clears the last error
	ClearError() error

	// SetDaemonStarted sets the daemon started timestamp
	SetDaemonStarted(startedAt time.Time) error

	// SetDaemonStopped clears the daemon runtime information
	SetDaemonStopped() error
}

StatusService provides status information about the application

type TokenDistribution

type TokenDistribution struct {
	InputPercentage         float64
	OutputPercentage        float64
	CacheCreationPercentage float64
	CacheReadPercentage     float64
}

TokenDistribution represents the distribution of token types

type TokenStatsFilter

type TokenStatsFilter struct {
	StartDate   *time.Time
	EndDate     *time.Time
	ProjectPath string
	Model       string
	SessionID   string
}

TokenStatsFilter defines filters for token statistics calculation

type TokenStatsResult

type TokenStatsResult struct {
	InputTokens         int
	OutputTokens        int
	CacheCreationTokens int
	CacheReadTokens     int
	TotalTokens         int
	Cost                float64
	Currency            string
	EntryCount          int
	DateRange           DateRange
}

TokenStatsResult contains the result of token statistics calculation

type UseCaseError

type UseCaseError struct {
	Code    string
	Message string
	Details map[string]interface{}
}

UseCaseError represents an error from use case operations

func NewUseCaseError

func NewUseCaseError(code, message string) *UseCaseError

NewUseCaseError creates a new use case error

func (*UseCaseError) Error

func (e *UseCaseError) Error() string

func (*UseCaseError) WithDetail

func (e *UseCaseError) WithDetail(key string, value interface{}) *UseCaseError

WithDetail adds a detail to the error

type VertexAIService added in v1.0.10

type VertexAIService interface {
	// GetCurrentUsage retrieves the current Vertex AI usage statistics
	// for all configured projects and locations
	GetCurrentUsage() (*entity.VertexAIUsage, error)

	// GetUsageForProject retrieves usage statistics for a specific project
	GetUsageForProject(projectID string) (*entity.VertexAIUsage, error)

	// GetDailyUsage retrieves aggregated usage for a specific date
	// Uses JST timezone for date boundaries
	GetDailyUsage(date time.Time) (*entity.VertexAIUsage, error)

	// GetCurrentMonthUsage retrieves usage for the current month
	GetCurrentMonthUsage() (*entity.VertexAIUsage, error)

	// IsEnabled checks if Vertex AI tracking is enabled in configuration
	IsEnabled() bool

	// CheckConnection verifies Google Cloud credentials and Cloud Monitoring access
	CheckConnection() error

	// GetConfiguredProjects returns the list of configured project IDs
	GetConfiguredProjects() []string
}

VertexAIService defines the interface for Vertex AI-related operations

Jump to

Keyboard shortcuts

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