MCPcopy Create free account
hub / github.com/astercloud/aster / GetSession

Method GetSession

server/handlers/dashboard.go:651–724  ·  view source on GitHub ↗

GetSession returns detailed session info

(c *gin.Context)

Source from the content-addressed store, hash-verified

649
650// GetSession returns detailed session info
651func (h *DashboardHandler) GetSession(c *gin.Context) {
652 ctx := c.Request.Context()
653 sessionID := c.Param("id")
654
655 var record SessionRecord
656 if err := (*h.store).Get(ctx, "sessions", sessionID, &record); err != nil {
657 c.JSON(http.StatusNotFound, gin.H{
658 "success": false,
659 "error": gin.H{
660 "code": "not_found",
661 "message": "Session not found",
662 },
663 })
664 return
665 }
666
667 // 转换消息
668 messages := make([]MessageSummary, 0, len(record.Messages))
669
670 for i, msg := range record.Messages {
671 // 获取消息内容
672 content := msg.Content
673 if content == "" && len(msg.ContentBlocks) > 0 {
674 // 从 ContentBlocks 提取文本
675 var contentSb673 strings.Builder
676 for _, block := range msg.ContentBlocks {
677 if textBlock, ok := block.(*types.TextBlock); ok {
678 contentSb673.WriteString(textBlock.Text)
679 }
680 }
681 content += contentSb673.String()
682 }
683
684 // 使用消息索引作为时间戳的偏移
685 timestamp := record.CreatedAt.Add(time.Duration(i) * time.Second)
686
687 messages = append(messages, MessageSummary{
688 Role: string(msg.Role),
689 Content: content,
690 Timestamp: timestamp,
691 })
692 }
693
694 // Token usage from session metadata
695 var tokenUsage TokenCount
696 if record.Metadata != nil {
697 if usage, ok := record.Metadata["token_usage"].(map[string]any); ok {
698 if input, ok := usage["input"].(float64); ok {
699 tokenUsage.Input = int64(input)
700 }
701 if output, ok := usage["output"].(float64); ok {
702 tokenUsage.Output = int64(output)
703 }
704 }
705 }
706 tokenUsage.Total = tokenUsage.Input + tokenUsage.Output
707
708 c.JSON(http.StatusOK, gin.H{

Callers

nothing calls this directly

Calls 6

JSONMethod · 0.80
ContextMethod · 0.65
GetMethod · 0.65
AddMethod · 0.65
StringMethod · 0.45
DurationMethod · 0.45

Tested by

no test coverage detected