Merge pull request #1344 from trheyi/main

Enhance stream data structures in Assistant for improved context and …
This commit is contained in:
Max 2025-11-25 11:12:30 +08:00 committed by GitHub
commit 02105da82b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 12 deletions

View file

@ -710,6 +710,7 @@ func (ast *Assistant) sendAgentStreamStart(ctx *context.Context, handler context
RequestID: ctx.RequestID(), RequestID: ctx.RequestID(),
Timestamp: startTime.UnixMilli(), Timestamp: startTime.UnixMilli(),
Assistant: ast.Info(ctx.Locale), Assistant: ast.Info(ctx.Locale),
Metadata: ctx.Metadata,
} }
if startJSON, err := jsoniter.Marshal(startData); err == nil { if startJSON, err := jsoniter.Marshal(startData); err == nil {
@ -731,9 +732,12 @@ func (ast *Assistant) sendAgentStreamEnd(ctx *context.Context, handler context.S
endData := &context.StreamEndData{ endData := &context.StreamEndData{
RequestID: ctx.RequestID(), RequestID: ctx.RequestID(),
ContextID: ctx.ID,
Timestamp: time.Now().UnixMilli(), Timestamp: time.Now().UnixMilli(),
DurationMs: time.Since(startTime).Milliseconds(), DurationMs: time.Since(startTime).Milliseconds(),
Status: status, Status: status,
TraceID: ctx.TraceID(),
Metadata: ctx.Metadata,
} }
if err != nil { if err != nil {

View file

@ -227,17 +227,21 @@ type StreamStartData struct {
ChatID string `json:"chat_id"` // Chat ID being used (e.g., "chat-123") ChatID string `json:"chat_id"` // Chat ID being used (e.g., "chat-123")
TraceID string `json:"trace_id"` // Trace ID being used (e.g., "trace-123") TraceID string `json:"trace_id"` // Trace ID being used (e.g., "trace-123")
Assistant *AssistantInfo `json:"assistant,omitempty"` // Assistant information Assistant *AssistantInfo `json:"assistant,omitempty"` // Assistant information
Metadata map[string]interface{} `json:"metadata,omitempty"` // Metadata to pass to the page for CUI context
} }
// StreamEndData represents the data for stream_end event // StreamEndData represents the data for stream_end event
// Sent when a streaming request completes (successfully or with error) // Sent when a streaming request completes (successfully or with error)
type StreamEndData struct { type StreamEndData struct {
RequestID string `json:"request_id"` // Corresponding request ID RequestID string `json:"request_id"` // Corresponding request ID
ContextID string `json:"context_id"` // Context ID for the response
TraceID string `json:"trace_id"` // Trace ID being used (e.g., "trace-123")
Timestamp int64 `json:"timestamp"` // Unix timestamp when stream ended Timestamp int64 `json:"timestamp"` // Unix timestamp when stream ended
DurationMs int64 `json:"duration_ms"` // Total duration in milliseconds DurationMs int64 `json:"duration_ms"` // Total duration in milliseconds
Status string `json:"status"` // "completed" | "error" | "cancelled" Status string `json:"status"` // "completed" | "error" | "cancelled"
Error string `json:"error,omitempty"` // Error message if status is "error" Error string `json:"error,omitempty"` // Error message if status is "error"
Usage *UsageInfo `json:"usage,omitempty"` // Token usage statistics Usage *UsageInfo `json:"usage,omitempty"` // Token usage statistics
Metadata map[string]interface{} `json:"metadata,omitempty"` // Metadata to pass to the page for CUI context
} }
// GroupStartData represents the data for group_start event // GroupStartData represents the data for group_start event