Documentation
¶
Index ¶
- type BYOKOverviewResponse
- type BillingTrendBucket
- type ChannelModelBreakdownRequest
- type ChannelModelBreakdownResponse
- type DashboardDataFinder
- type DashboardRequest
- type DashboardResponse
- type DataStatus
- type Handler
- func (h *Handler) BYOKOverview(c *app.Context, _ api.EmptyRequest) (BYOKOverviewResponse, error)
- func (h *Handler) ChannelModelBreakdown(c *app.Context, req ChannelModelBreakdownRequest) (ChannelModelBreakdownResponse, error)
- func (h *Handler) Dashboard(c *app.Context, req DashboardRequest) (DashboardResponse, error)
- func (h *Handler) MarketShare(c *app.Context, req MarketShareRequest) (MarketShareResponse, error)
- func (h *Handler) MetricTrend(c *app.Context, req MetricTrendRequest) (MetricTrendResponse, error)
- func (h *Handler) ModelDistribution(c *app.Context, req ModelDistributionRequest) (ModelDistributionResponse, error)
- func (h *Handler) Overview(c *app.Context, _ api.EmptyRequest) (OverviewResponse, error)
- func (h *Handler) Trend(c *app.Context, req TrendRequest) (TrendResponse, error)
- type LeaderboardBlock
- type LogMetrics
- type MarketShareRequest
- type MarketShareResponse
- type MetricTrendRequest
- type MetricTrendResponse
- type ModelDistributionRequest
- type ModelDistributionResponse
- type OverviewResponse
- type PerformanceBucket
- type PerformanceTrendBlock
- type SpeedCompareBlock
- type TrendBlock
- type TrendRequest
- type TrendResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BYOKOverviewResponse ¶ added in v0.0.2
type BYOKOverviewResponse struct {
Requests int64 `json:"requests"`
TotalCost int64 `json:"total_cost"`
}
BYOKOverviewResponse holds aggregated BYOK usage stats for the current user. Kept for backward-compat with the original /api/stats/byok-overview endpoint; new clients should use /api/private-channels/billing/overview which returns KPI + daily time series.
type BillingTrendBucket ¶ added in v0.0.14
type ChannelModelBreakdownRequest ¶ added in v0.0.14
type ChannelModelBreakdownRequest struct {
ChannelID uint `form:"channel_id"`
Start int64 `form:"start"`
End int64 `form:"end"`
Gran string `form:"gran"`
}
ChannelModelBreakdownRequest 是 /stats/channel-model-breakdown 的入参。 start/end 为 unix 秒;end 缺省取 now、start 缺省取 end-86400(同 DashboardRequest 约定)。
type ChannelModelBreakdownResponse ¶ added in v0.0.14
type ChannelModelBreakdownResponse struct {
Rows []dao.ChannelModelBreakdownRow `json:"rows"`
}
ChannelModelBreakdownResponse 是 /stats/channel-model-breakdown 的返回。
type DashboardDataFinder ¶ added in v0.0.14
type DashboardDataFinder interface {
DashboardKpis(dao.ObsRange, dao.Scope, dao.ObsFilter) (dao.KpiBundle, error)
DashboardTrend(dao.ObsRange, dao.Scope, dao.ObsFilter) ([]dao.TimeBucket, error)
DashboardSuccessRate(dao.ObsRange, dao.Scope, dao.ObsFilter) (dao.KpiMetric, error)
HourlyTrend(dao.ObsRange, dao.Scope, dao.ObsFilter) ([]dao.TimeBucket, error)
Leaderboard(string, string, int, dao.ObsRange, dao.Scope, dao.ObsFilter) ([]dao.LeaderRow, error)
SpeedCompare(string, dao.ObsRange, dao.Scope, int, dao.ObsFilter) ([]dao.SpeedRow, error)
}
type DashboardRequest ¶ added in v0.0.2
type DashboardRequest struct {
Start int64 `form:"start"`
End int64 `form:"end"`
Gran string `form:"gran"`
Model string `form:"model"`
UserID uint `form:"user_id"`
TopN int `form:"top_n"`
}
DashboardRequest 是 /v1/stats/dashboard 的入参。 start/end 为 unix 秒;end 缺省取 now、start 缺省取 end-86400;gran 缺省 "day"。
type DashboardResponse ¶ added in v0.0.2
type DashboardResponse struct {
Kpis dao.KpiBundle `json:"kpis"`
Trend TrendBlock `json:"trend"`
LogMetrics *LogMetrics `json:"log_metrics"`
DataStatus DataStatus `json:"data_status"`
}
DashboardResponse keeps request and billing metrics concrete and groups optional performance charts under the nullable LogMetrics section.
type DataStatus ¶ added in v0.0.14
type DataStatus struct {
LogDB string `json:"log_db"`
}
type Handler ¶
type Handler struct {
ConnectedCount func() int
Cache *dao.StatsCache
LogDatabaseReady func() bool
DashboardDataFinder func(app.Application, context.Context) DashboardDataFinder
}
func (*Handler) BYOKOverview ¶ added in v0.0.2
func (h *Handler) BYOKOverview(c *app.Context, _ api.EmptyRequest) (BYOKOverviewResponse, error)
BYOKOverview returns private-channel usage summary for the authenticated user.
Task 19+ moved the source of truth from usage_logs to channel_daily_billings. Reusing ListPrivateChannelDailyByOwner keeps this endpoint consistent with the new /private-channels/billing/* endpoints (same rows, same scoping rules) at the cost of one extra SUM in Go — the per-user row count is negligible.
func (*Handler) ChannelModelBreakdown ¶ added in v0.0.14
func (h *Handler) ChannelModelBreakdown(c *app.Context, req ChannelModelBreakdownRequest) (ChannelModelBreakdownResponse, error)
ChannelModelBreakdown 返回单渠道按 model_name 分组的用量/计费细分(billed 折后 + raw 折前),给 Billing 展开行 + 渠道详情卡片共用。admin-only:非 admin 直接 403。
func (*Handler) Dashboard ¶ added in v0.0.2
func (h *Handler) Dashboard(c *app.Context, req DashboardRequest) (DashboardResponse, error)
Dashboard 组合 Phase 2 的 DAO 方法 (DashboardKpis / HourlyTrend / Leaderboard / SpeedCompare),按 admin/user scope 返回不同的字段集。
admin: 全部字段 (kpis + trend + leaderboard + speed_compare)。 user: 仅 kpis + trend;admin-only 字段通过 omitempty 隐藏。
窗口超过 ObsRange.Validate() 上限时返回 400 RangeOutOfBounds (结构化 code,前端 i18n 用)。
func (*Handler) MarketShare ¶ added in v0.0.14
func (h *Handler) MarketShare(c *app.Context, req MarketShareRequest) (MarketShareResponse, error)
MarketShare 返回按 model/channel 维度分组的 token 量堆叠时间序列。admin-only。
func (*Handler) MetricTrend ¶ added in v0.0.14
func (h *Handler) MetricTrend(c *app.Context, req MetricTrendRequest) (MetricTrendResponse, error)
MetricTrend returns a per-model/channel time series for one metric, split into up to top-N series + an "others" fold. Ordinary users are locked to their own usage; admins may query global usage or lock to one user.
func (*Handler) ModelDistribution ¶ added in v0.0.14
func (h *Handler) ModelDistribution(c *app.Context, req ModelDistributionRequest) (ModelDistributionResponse, error)
func (*Handler) Overview ¶
func (h *Handler) Overview(c *app.Context, _ api.EmptyRequest) (OverviewResponse, error)
func (*Handler) Trend ¶
func (h *Handler) Trend(c *app.Context, req TrendRequest) (TrendResponse, error)
type LeaderboardBlock ¶ added in v0.0.2
type LeaderboardBlock struct {
Users []dao.LeaderRow `json:"users"`
Models []dao.LeaderRow `json:"models"`
Channels []dao.LeaderRow `json:"channels"`
AvailableMetrics []string `json:"available_metrics"`
}
LeaderboardBlock 聚合三个维度 (user/model/channel) 的 cost top10 + 可选 metric 列表。
type LogMetrics ¶ added in v0.0.14
type LogMetrics struct {
Trend PerformanceTrendBlock `json:"trend"`
Leaderboard *LeaderboardBlock `json:"leaderboard,omitempty"`
SpeedCompare *SpeedCompareBlock `json:"speed_compare,omitempty"`
}
type MarketShareRequest ¶ added in v0.0.14
type MarketShareRequest struct {
}
MarketShareRequest 是 /stats/market-share 的入参。 dim 只接受 "model"|"channel"(author 本期不支持,见 dao.ErrUnsupportedMarketShareDim); start/end 缺省同 DashboardRequest 约定(end 缺省 now、start 缺省 end-86400)。
type MarketShareResponse ¶ added in v0.0.14
type MarketShareResponse struct {
}
MarketShareResponse 是 /stats/market-share 的返回,直接透传 dao.CostTrendStacked (buckets + series_order),供前端纵向堆叠柱状图使用。
type MetricTrendRequest ¶ added in v0.0.14
type MetricTrendRequest struct {
Metric string `form:"metric"`
Stat string `form:"stat"`
Dim string `form:"dim"`
Start int64 `form:"start"`
End int64 `form:"end"`
Gran string `form:"gran"`
Model string `form:"model"`
TopN int `form:"top_n"`
UserID uint `form:"user_id"`
}
MetricTrendRequest is /stats/metric-trend's input. Metric selects which value is charted (cost|requests|tokens|ttft|tps|cache_hit_rate); Dim selects the grouping (model|channel, author unsupported — no author data source).
type MetricTrendResponse ¶ added in v0.0.14
type MetricTrendResponse struct {
Metric string `json:"metric"`
Stat string `json:"stat"`
Unit string `json:"unit"`
Estimated bool `json:"estimated"`
Buckets []dao.MetricStackedBucket `json:"buckets"`
SeriesOrder []string `json:"series_order"`
}
MetricTrendResponse directly transcribes dao.MetricTrendStacked (buckets + series_order) for the frontend's multi-line trend chart.
type ModelDistributionRequest ¶ added in v0.0.14
type ModelDistributionResponse ¶ added in v0.0.14
type OverviewResponse ¶
type OverviewResponse struct {
// Admin-only fields (nil for normal users)
Users *int64 `json:"users,omitempty"`
Channels *int64 `json:"channels,omitempty"`
Models *int64 `json:"models,omitempty"`
Agents *int64 `json:"agents,omitempty"`
ConnectedAgents *int `json:"connected_agents,omitempty"`
// Common fields
Tokens int64 `json:"tokens"`
UsageLogs int64 `json:"usage_logs"`
TotalCost int64 `json:"total_cost"`
// User-only fields (nil for admin)
Quota *int64 `json:"quota,omitempty"`
UsedQuota *int64 `json:"used_quota,omitempty"`
}
type PerformanceBucket ¶ added in v0.0.14
type PerformanceTrendBlock ¶ added in v0.0.14
type PerformanceTrendBlock struct {
Buckets []PerformanceBucket `json:"buckets"`
Metrics []string `json:"metrics"`
}
type SpeedCompareBlock ¶ added in v0.0.2
type SpeedCompareBlock struct {
ByModel []dao.SpeedRow `json:"by_model"`
ByChannel []dao.SpeedRow `json:"by_channel"`
}
SpeedCompareBlock 聚合 model/channel 维度 SpeedCompare。
type TrendBlock ¶ added in v0.0.2
type TrendBlock struct {
Buckets []BillingTrendBucket `json:"buckets"`
Metrics []string `json:"metrics"`
}
TrendBlock contains cost, request, and token metrics from log-owned facts.
type TrendRequest ¶
type TrendRequest struct {
Days string `form:"days"`
}