Enhance response structure and stream start data in Assistant for improved context handling

- Updated the Response struct to include ContextID, RequestID, ChatID, and AssistantID for better traceability and context management.
- Modified the Stream method to return the new fields in the response, enhancing the output for client interactions.
- Added ContextID and ChatID to the StreamStartData struct to improve event tracking during streaming requests.
This commit is contained in:
Max 2025-11-22 17:32:51 +08:00
parent 21c0ec5034
commit ea167b35a7
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,11 +263,15 @@ type Stack struct {
// Response the response
// 100% compatible with the OpenAI API
type Response struct {
Create *HookCreateResponse `json:"create,omitempty"`
MCP *ResponseHookMCP `json:"mcp,omitempty"`
Done *ResponseHookDone `json:"done,omitempty"`
Failback *ResponseHookFailback `json:"failback,omitempty"`
Completion *CompletionResponse `json:"completion,omitempty"`
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"`
Failback *ResponseHookFailback `json:"failback,omitempty"`
Completion *CompletionResponse `json:"completion,omitempty"`
}
// HookCreateResponse the response of the create hook

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")