Merge pull request #1339 from trheyi/main

Enhance response structure and stream start data in Assistant for imp…
This commit is contained in:
Max 2025-11-22 17:34:12 +08:00 committed by GitHub
commit b111bfacaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 8 deletions

View file

@ -249,7 +249,12 @@ func (ast *Assistant) Stream(ctx *context.Context, inputMessages []context.Messa
}
}
return &context.Response{Create: createResponse, Done: doneResponse, Completion: completionResponse}, nil
return &context.Response{
ContextID: ctx.ID,
RequestID: ctx.RequestID(),
ChatID: ctx.ChatID,
AssistantID: ast.ID,
Create: createResponse, Done: doneResponse, Completion: completionResponse}, nil
}
// GetConnector get the connector object, capabilities, and error with priority: createResponse > ctx > ast
@ -676,11 +681,12 @@ func (ast *Assistant) sendAgentStreamStart(ctx *context.Context, handler context
// Build the start data
startData := context.StreamStartData{
ContextID: ctx.ID,
ChatID: ctx.ChatID,
TraceID: ctx.TraceID(),
RequestID: ctx.RequestID(),
Timestamp: startTime.UnixMilli(),
Assistant: ast.Info(ctx.Locale),
ChatID: ctx.ChatID,
TraceID: ctx.TraceID(),
}
if startJSON, err := jsoniter.Marshal(startData); err == nil {

View file

@ -263,6 +263,10 @@ type Stack struct {
// Response the response
// 100% compatible with the OpenAI API
type Response struct {
RequestID string `json:"request_id"` // Request ID for the response
ContextID string `json:"context_id"` // Context ID for the response
ChatID string `json:"chat_id"` // Chat ID for the response
AssistantID string `json:"assistant_id"` // Assistant ID for the response
Create *HookCreateResponse `json:"create,omitempty"`
MCP *ResponseHookMCP `json:"mcp,omitempty"`
Done *ResponseHookDone `json:"done,omitempty"`

View file

@ -221,6 +221,7 @@ type JSONSchema struct {
// StreamStartData represents the data for stream_start event
// Sent when a streaming request begins
type StreamStartData struct {
ContextID string `json:"context_id"` // Context ID for the response
RequestID string `json:"request_id"` // Unique identifier for this request
Timestamp int64 `json:"timestamp"` // Unix timestamp when stream started
ChatID string `json:"chat_id"` // Chat ID being used (e.g., "chat-123")