2025-11-08 16:02:31 +00:00
|
|
|
package session
|
2025-11-05 15:18:44 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
feat(agent): human-in-the-loop approval for MCP tool calls (#1173)
Add an opt-in human approval gate so Agent runs pause before executing
MCP tools that operators flag as dangerous, surface an approval card in
the chat UI, and only resume after the user approves (optionally with
edited args) or rejects.
Backend
- New mcp_tool_approvals table + repo/service to mark per-tool approval
required (PG migration 000042 + sqlite init).
- approval.Gate coordinates RequestAndWait / Resolve with sync.Once
delivery, configurable timeout, and Redis Pub/Sub fan-out so multi-
replica deployments work without sticky sessions.
- MCPTool.Execute integrates the gate; uses a round-level ApprovalCtx
(without the per-tool 60s timeout) for the wait, and re-derives a
fresh 60s exec ctx after approval so CallTool keeps a full window.
- New SSE response types (tool_approval_required / _resolved) and
EventBus events plumb approval state to AgentStreamDisplay.
- REST: list/set per-tool approval flag, resolve pending approval.
- Configurable via agent.tool_approval_timeout_seconds (yaml) or
WEKNORA_AGENT_TOOL_APPROVAL_TIMEOUT env (accepts seconds or Go
duration).
Frontend
- MCP settings: per-tool "require approval" switch on the test panel.
- Chat: ToolApprovalCard renders the pause point with editable JSON
args, validation feedback, mm:ss countdown that turns warning/danger
near deadline, and a resolved state that retains context.
- i18n strings added for zh-CN / en-US / ko-KR / ru-RU.
Docs
- docs/zh/mcp-approval.md covering behavior, config, API, deployment
considerations (Redis cross-instance, restart limitations).
2026-05-10 13:23:49 +00:00
|
|
|
"encoding/json"
|
2025-11-05 15:18:44 +00:00
|
|
|
"fmt"
|
2026-06-03 18:35:54 +00:00
|
|
|
"strings"
|
2025-11-05 15:18:44 +00:00
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-06-15 16:49:20 +00:00
|
|
|
agenttools "github.com/Tencent/WeKnora/internal/agent/tools"
|
2025-11-05 15:18:44 +00:00
|
|
|
"github.com/Tencent/WeKnora/internal/event"
|
|
|
|
|
"github.com/Tencent/WeKnora/internal/logger"
|
|
|
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
|
|
|
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// AgentStreamHandler handles agent events for SSE streaming
|
|
|
|
|
// It uses a dedicated EventBus per request to avoid SessionID filtering
|
2025-11-07 14:41:41 +00:00
|
|
|
// Events are appended to StreamManager without accumulation
|
2025-11-05 15:18:44 +00:00
|
|
|
type AgentStreamHandler struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
sessionID string
|
|
|
|
|
assistantMessageID string
|
|
|
|
|
requestID string
|
2026-05-12 13:12:03 +00:00
|
|
|
receivedAt time.Time // Handler entry timestamp, used for TTFB logging
|
|
|
|
|
ttfbLogged bool // Guards one-shot TTFB log on first answer chunk
|
2025-11-05 15:18:44 +00:00
|
|
|
assistantMessage *types.Message
|
|
|
|
|
streamManager interfaces.StreamManager
|
|
|
|
|
|
|
|
|
|
eventBus *event.EventBus
|
|
|
|
|
|
|
|
|
|
// State tracking
|
2025-11-07 14:41:41 +00:00
|
|
|
knowledgeRefs []*types.SearchResult
|
|
|
|
|
finalAnswer string
|
2026-06-03 18:35:54 +00:00
|
|
|
answerSegments []*answerSegment // Per-answer-event-ID accumulation, so superseded preambles can be dropped
|
2025-11-07 14:41:41 +00:00
|
|
|
eventStartTimes map[string]time.Time // Track start time for duration calculation
|
|
|
|
|
mu sync.Mutex
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-03 18:35:54 +00:00
|
|
|
// answerSegment accumulates the streamed content of a single final-answer event
|
|
|
|
|
// ID. A non-terminal round may stream a preamble ("let me search…") under its
|
|
|
|
|
// own answer ID and then be marked superseded once the round turns out to call
|
|
|
|
|
// tools; tracking segments separately lets us exclude that preamble from the
|
|
|
|
|
// persisted assistant message instead of leaking it into the final answer.
|
|
|
|
|
type answerSegment struct {
|
|
|
|
|
id string
|
|
|
|
|
content string
|
|
|
|
|
superseded bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// findAnswerSegment returns the segment for an answer event ID, or nil.
|
|
|
|
|
// Callers must hold h.mu.
|
|
|
|
|
func (h *AgentStreamHandler) findAnswerSegment(id string) *answerSegment {
|
|
|
|
|
for _, seg := range h.answerSegments {
|
|
|
|
|
if seg.id == id {
|
|
|
|
|
return seg
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// composeFinalAnswer rebuilds the persisted answer from all non-superseded
|
|
|
|
|
// segments in arrival order. Callers must hold h.mu.
|
|
|
|
|
func (h *AgentStreamHandler) composeFinalAnswer() string {
|
|
|
|
|
var b strings.Builder
|
|
|
|
|
for _, seg := range h.answerSegments {
|
|
|
|
|
if !seg.superseded {
|
|
|
|
|
b.WriteString(seg.content)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return b.String()
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 15:18:44 +00:00
|
|
|
// NewAgentStreamHandler creates a new handler for agent SSE streaming
|
|
|
|
|
func NewAgentStreamHandler(
|
|
|
|
|
ctx context.Context,
|
|
|
|
|
sessionID, assistantMessageID, requestID string,
|
2026-05-12 13:12:03 +00:00
|
|
|
receivedAt time.Time,
|
2025-11-05 15:18:44 +00:00
|
|
|
assistantMessage *types.Message,
|
|
|
|
|
streamManager interfaces.StreamManager,
|
|
|
|
|
eventBus *event.EventBus,
|
|
|
|
|
) *AgentStreamHandler {
|
|
|
|
|
return &AgentStreamHandler{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
sessionID: sessionID,
|
|
|
|
|
assistantMessageID: assistantMessageID,
|
|
|
|
|
requestID: requestID,
|
2026-05-12 13:12:03 +00:00
|
|
|
receivedAt: receivedAt,
|
2025-11-05 15:18:44 +00:00
|
|
|
assistantMessage: assistantMessage,
|
|
|
|
|
streamManager: streamManager,
|
|
|
|
|
eventBus: eventBus,
|
|
|
|
|
knowledgeRefs: make([]*types.SearchResult, 0),
|
|
|
|
|
eventStartTimes: make(map[string]time.Time),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Subscribe subscribes to all agent streaming events on the dedicated EventBus
|
|
|
|
|
// No SessionID filtering needed since we have a dedicated EventBus per request
|
|
|
|
|
func (h *AgentStreamHandler) Subscribe() {
|
|
|
|
|
// Subscribe to all agent streaming events on the dedicated EventBus
|
|
|
|
|
h.eventBus.On(event.EventAgentThought, h.handleThought)
|
|
|
|
|
h.eventBus.On(event.EventAgentToolCall, h.handleToolCall)
|
|
|
|
|
h.eventBus.On(event.EventAgentToolResult, h.handleToolResult)
|
|
|
|
|
h.eventBus.On(event.EventAgentReferences, h.handleReferences)
|
|
|
|
|
h.eventBus.On(event.EventAgentFinalAnswer, h.handleFinalAnswer)
|
|
|
|
|
h.eventBus.On(event.EventAgentReflection, h.handleReflection)
|
|
|
|
|
h.eventBus.On(event.EventError, h.handleError)
|
2025-11-07 14:41:41 +00:00
|
|
|
h.eventBus.On(event.EventSessionTitle, h.handleSessionTitle)
|
2025-11-07 16:58:26 +00:00
|
|
|
h.eventBus.On(event.EventAgentComplete, h.handleComplete)
|
feat(agent): human-in-the-loop approval for MCP tool calls (#1173)
Add an opt-in human approval gate so Agent runs pause before executing
MCP tools that operators flag as dangerous, surface an approval card in
the chat UI, and only resume after the user approves (optionally with
edited args) or rejects.
Backend
- New mcp_tool_approvals table + repo/service to mark per-tool approval
required (PG migration 000042 + sqlite init).
- approval.Gate coordinates RequestAndWait / Resolve with sync.Once
delivery, configurable timeout, and Redis Pub/Sub fan-out so multi-
replica deployments work without sticky sessions.
- MCPTool.Execute integrates the gate; uses a round-level ApprovalCtx
(without the per-tool 60s timeout) for the wait, and re-derives a
fresh 60s exec ctx after approval so CallTool keeps a full window.
- New SSE response types (tool_approval_required / _resolved) and
EventBus events plumb approval state to AgentStreamDisplay.
- REST: list/set per-tool approval flag, resolve pending approval.
- Configurable via agent.tool_approval_timeout_seconds (yaml) or
WEKNORA_AGENT_TOOL_APPROVAL_TIMEOUT env (accepts seconds or Go
duration).
Frontend
- MCP settings: per-tool "require approval" switch on the test panel.
- Chat: ToolApprovalCard renders the pause point with editable JSON
args, validation feedback, mm:ss countdown that turns warning/danger
near deadline, and a resolved state that retains context.
- i18n strings added for zh-CN / en-US / ko-KR / ru-RU.
Docs
- docs/zh/mcp-approval.md covering behavior, config, API, deployment
considerations (Redis cross-instance, restart limitations).
2026-05-10 13:23:49 +00:00
|
|
|
h.eventBus.On(event.EventToolApprovalRequired, h.handleToolApprovalRequired)
|
|
|
|
|
h.eventBus.On(event.EventToolApprovalResolved, h.handleToolApprovalResolved)
|
2026-06-29 14:37:02 +00:00
|
|
|
h.eventBus.On(event.EventMCPOAuthRequired, h.handleMCPOAuthRequired)
|
|
|
|
|
h.eventBus.On(event.EventMCPOAuthResolved, h.handleMCPOAuthResolved)
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleThought handles agent thought events
|
|
|
|
|
func (h *AgentStreamHandler) handleThought(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.AgentThoughtData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h.mu.Lock()
|
|
|
|
|
|
|
|
|
|
// Track start time on first chunk
|
|
|
|
|
if _, exists := h.eventStartTimes[evt.ID]; !exists {
|
|
|
|
|
h.eventStartTimes[evt.ID] = time.Now()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate duration if done
|
|
|
|
|
var metadata map[string]interface{}
|
|
|
|
|
if data.Done {
|
|
|
|
|
startTime := h.eventStartTimes[evt.ID]
|
|
|
|
|
duration := time.Since(startTime)
|
|
|
|
|
metadata = map[string]interface{}{
|
|
|
|
|
"event_id": evt.ID,
|
|
|
|
|
"duration_ms": duration.Milliseconds(),
|
|
|
|
|
"completed_at": time.Now().Unix(),
|
|
|
|
|
}
|
|
|
|
|
delete(h.eventStartTimes, evt.ID)
|
|
|
|
|
} else {
|
|
|
|
|
metadata = map[string]interface{}{
|
|
|
|
|
"event_id": evt.ID,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h.mu.Unlock()
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Append this chunk to stream (no accumulation - frontend will accumulate)
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeThinking,
|
|
|
|
|
Content: data.Content, // Just this chunk
|
|
|
|
|
Done: data.Done,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: metadata,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Error("Append thought event to stream failed", "error", err)
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleToolCall handles tool call events
|
|
|
|
|
func (h *AgentStreamHandler) handleToolCall(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.AgentToolCallData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-12 06:27:00 +00:00
|
|
|
h.mu.Lock()
|
|
|
|
|
// Track start time for this tool call (use tool_call_id as key)
|
|
|
|
|
h.eventStartTimes[data.ToolCallID] = time.Now()
|
2026-06-03 18:35:54 +00:00
|
|
|
// Any answer text streamed before this tool call was a non-terminal round's
|
|
|
|
|
// preamble, not the final answer (the agent only ends by stopping naturally
|
|
|
|
|
// with plain text and no tool calls). Drop those segments from the persisted
|
|
|
|
|
// answer so the preamble never leaks into Message.Content.
|
|
|
|
|
supersededAny := false
|
|
|
|
|
for _, seg := range h.answerSegments {
|
|
|
|
|
if !seg.superseded && seg.content != "" {
|
|
|
|
|
seg.superseded = true
|
|
|
|
|
supersededAny = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if supersededAny {
|
|
|
|
|
h.finalAnswer = h.composeFinalAnswer()
|
|
|
|
|
}
|
2025-11-12 06:27:00 +00:00
|
|
|
h.mu.Unlock()
|
|
|
|
|
|
2025-11-05 15:18:44 +00:00
|
|
|
metadata := map[string]interface{}{
|
2025-11-12 06:27:00 +00:00
|
|
|
"tool_name": data.ToolName,
|
|
|
|
|
"arguments": data.Arguments,
|
|
|
|
|
"tool_call_id": data.ToolCallID,
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Append event to stream
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
2025-11-05 15:18:44 +00:00
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeToolCall,
|
|
|
|
|
Content: fmt.Sprintf("Calling tool: %s", data.ToolName),
|
|
|
|
|
Done: false,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: metadata,
|
|
|
|
|
}); err != nil {
|
2025-11-07 14:41:41 +00:00
|
|
|
logger.GetLogger(h.ctx).Error("Append tool call event to stream failed", "error", err)
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleToolResult handles tool result events
|
|
|
|
|
func (h *AgentStreamHandler) handleToolResult(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.AgentToolResultData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-12 06:27:00 +00:00
|
|
|
h.mu.Lock()
|
|
|
|
|
// Calculate duration from start time if available, otherwise use provided duration
|
|
|
|
|
var durationMs int64
|
|
|
|
|
if startTime, exists := h.eventStartTimes[data.ToolCallID]; exists {
|
|
|
|
|
durationMs = time.Since(startTime).Milliseconds()
|
|
|
|
|
delete(h.eventStartTimes, data.ToolCallID)
|
|
|
|
|
} else if data.Duration > 0 {
|
|
|
|
|
// Fallback to provided duration if start time not tracked
|
|
|
|
|
durationMs = data.Duration
|
|
|
|
|
}
|
|
|
|
|
h.mu.Unlock()
|
|
|
|
|
|
2025-11-05 15:18:44 +00:00
|
|
|
// Send SSE response (both success and failure)
|
|
|
|
|
responseType := types.ResponseTypeToolResult
|
2026-06-15 16:49:20 +00:00
|
|
|
content := agenttools.StreamContentForToolResult(data.ToolName, data.Success, data.Error, data.Data)
|
2025-11-05 15:18:44 +00:00
|
|
|
if !data.Success {
|
|
|
|
|
responseType = types.ResponseTypeError
|
2026-06-15 16:49:20 +00:00
|
|
|
if content == "" && data.Error != "" {
|
2025-11-05 15:18:44 +00:00
|
|
|
content = data.Error
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build metadata including tool result data for rich frontend rendering
|
|
|
|
|
metadata := map[string]interface{}{
|
2025-11-12 06:27:00 +00:00
|
|
|
"tool_name": data.ToolName,
|
|
|
|
|
"success": data.Success,
|
|
|
|
|
"error": data.Error,
|
|
|
|
|
"duration_ms": durationMs,
|
|
|
|
|
"tool_call_id": data.ToolCallID,
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-15 16:49:20 +00:00
|
|
|
clientData := agenttools.SanitizeToolResultForClient(data.ToolName, &types.ToolResult{
|
|
|
|
|
Success: data.Success,
|
|
|
|
|
Output: data.Output,
|
|
|
|
|
Error: data.Error,
|
|
|
|
|
Data: data.Data,
|
|
|
|
|
})
|
|
|
|
|
for k, v := range clientData {
|
|
|
|
|
metadata[k] = v
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Append event to stream
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
2025-11-05 15:18:44 +00:00
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: responseType,
|
|
|
|
|
Content: content,
|
|
|
|
|
Done: false,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: metadata,
|
|
|
|
|
}); err != nil {
|
2025-11-07 14:41:41 +00:00
|
|
|
logger.GetLogger(h.ctx).Error("Append tool result event to stream failed", "error", err)
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
feat(agent): human-in-the-loop approval for MCP tool calls (#1173)
Add an opt-in human approval gate so Agent runs pause before executing
MCP tools that operators flag as dangerous, surface an approval card in
the chat UI, and only resume after the user approves (optionally with
edited args) or rejects.
Backend
- New mcp_tool_approvals table + repo/service to mark per-tool approval
required (PG migration 000042 + sqlite init).
- approval.Gate coordinates RequestAndWait / Resolve with sync.Once
delivery, configurable timeout, and Redis Pub/Sub fan-out so multi-
replica deployments work without sticky sessions.
- MCPTool.Execute integrates the gate; uses a round-level ApprovalCtx
(without the per-tool 60s timeout) for the wait, and re-derives a
fresh 60s exec ctx after approval so CallTool keeps a full window.
- New SSE response types (tool_approval_required / _resolved) and
EventBus events plumb approval state to AgentStreamDisplay.
- REST: list/set per-tool approval flag, resolve pending approval.
- Configurable via agent.tool_approval_timeout_seconds (yaml) or
WEKNORA_AGENT_TOOL_APPROVAL_TIMEOUT env (accepts seconds or Go
duration).
Frontend
- MCP settings: per-tool "require approval" switch on the test panel.
- Chat: ToolApprovalCard renders the pause point with editable JSON
args, validation feedback, mm:ss countdown that turns warning/danger
near deadline, and a resolved state that retains context.
- i18n strings added for zh-CN / en-US / ko-KR / ru-RU.
Docs
- docs/zh/mcp-approval.md covering behavior, config, API, deployment
considerations (Redis cross-instance, restart limitations).
2026-05-10 13:23:49 +00:00
|
|
|
func toolApprovalDataToMap(v interface{}) map[string]interface{} {
|
|
|
|
|
b, err := json.Marshal(v)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return map[string]interface{}{}
|
|
|
|
|
}
|
|
|
|
|
var m map[string]interface{}
|
|
|
|
|
if err := json.Unmarshal(b, &m); err != nil {
|
|
|
|
|
return map[string]interface{}{}
|
|
|
|
|
}
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleToolApprovalRequired persists MCP tool human-approval prompts for SSE / replay (issue #1173).
|
|
|
|
|
func (h *AgentStreamHandler) handleToolApprovalRequired(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.ToolApprovalRequiredData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
meta := toolApprovalDataToMap(data)
|
|
|
|
|
meta["pending_id"] = data.PendingID
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeToolApprovalRequired,
|
|
|
|
|
Content: "MCP tool requires human approval",
|
|
|
|
|
Done: true,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: meta,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Error("Append tool approval required event failed", "error", err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleToolApprovalResolved persists the outcome of a tool approval (issue #1173).
|
|
|
|
|
func (h *AgentStreamHandler) handleToolApprovalResolved(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.ToolApprovalResolvedData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
meta := toolApprovalDataToMap(data)
|
|
|
|
|
meta["pending_id"] = data.PendingID
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeToolApprovalResolved,
|
|
|
|
|
Content: "MCP tool approval resolved",
|
|
|
|
|
Done: true,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: meta,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Error("Append tool approval resolved event failed", "error", err)
|
2026-06-29 14:37:02 +00:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleMCPOAuthRequired forwards an in-conversation "authorize this MCP
|
|
|
|
|
// service" prompt to the SSE stream so the UI can render an Authorize card.
|
|
|
|
|
func (h *AgentStreamHandler) handleMCPOAuthRequired(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.MCPOAuthRequiredData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
meta := toolApprovalDataToMap(data)
|
|
|
|
|
meta["pending_id"] = data.PendingID
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeMCPOAuthRequired,
|
|
|
|
|
Content: "MCP service requires OAuth authorization",
|
|
|
|
|
Done: true,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: meta,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Error("Append mcp oauth required event failed", "error", err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleMCPOAuthResolved forwards the outcome of an in-conversation OAuth prompt.
|
|
|
|
|
func (h *AgentStreamHandler) handleMCPOAuthResolved(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.MCPOAuthResolvedData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
meta := toolApprovalDataToMap(data)
|
|
|
|
|
meta["pending_id"] = data.PendingID
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeMCPOAuthResolved,
|
|
|
|
|
Content: "MCP OAuth authorization resolved",
|
|
|
|
|
Done: true,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: meta,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Error("Append mcp oauth resolved event failed", "error", err)
|
feat(agent): human-in-the-loop approval for MCP tool calls (#1173)
Add an opt-in human approval gate so Agent runs pause before executing
MCP tools that operators flag as dangerous, surface an approval card in
the chat UI, and only resume after the user approves (optionally with
edited args) or rejects.
Backend
- New mcp_tool_approvals table + repo/service to mark per-tool approval
required (PG migration 000042 + sqlite init).
- approval.Gate coordinates RequestAndWait / Resolve with sync.Once
delivery, configurable timeout, and Redis Pub/Sub fan-out so multi-
replica deployments work without sticky sessions.
- MCPTool.Execute integrates the gate; uses a round-level ApprovalCtx
(without the per-tool 60s timeout) for the wait, and re-derives a
fresh 60s exec ctx after approval so CallTool keeps a full window.
- New SSE response types (tool_approval_required / _resolved) and
EventBus events plumb approval state to AgentStreamDisplay.
- REST: list/set per-tool approval flag, resolve pending approval.
- Configurable via agent.tool_approval_timeout_seconds (yaml) or
WEKNORA_AGENT_TOOL_APPROVAL_TIMEOUT env (accepts seconds or Go
duration).
Frontend
- MCP settings: per-tool "require approval" switch on the test panel.
- Chat: ToolApprovalCard renders the pause point with editable JSON
args, validation feedback, mm:ss countdown that turns warning/danger
near deadline, and a resolved state that retains context.
- i18n strings added for zh-CN / en-US / ko-KR / ru-RU.
Docs
- docs/zh/mcp-approval.md covering behavior, config, API, deployment
considerations (Redis cross-instance, restart limitations).
2026-05-10 13:23:49 +00:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 15:18:44 +00:00
|
|
|
// handleReferences handles knowledge references events
|
|
|
|
|
func (h *AgentStreamHandler) handleReferences(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.AgentReferencesData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h.mu.Lock()
|
|
|
|
|
defer h.mu.Unlock()
|
|
|
|
|
|
|
|
|
|
// Extract knowledge references
|
|
|
|
|
// Try to cast directly to []*types.SearchResult first
|
|
|
|
|
if searchResults, ok := data.References.([]*types.SearchResult); ok {
|
|
|
|
|
h.knowledgeRefs = append(h.knowledgeRefs, searchResults...)
|
|
|
|
|
} else if refs, ok := data.References.([]interface{}); ok {
|
|
|
|
|
// Fallback: convert from []interface{}
|
|
|
|
|
for _, ref := range refs {
|
|
|
|
|
if sr, ok := ref.(*types.SearchResult); ok {
|
|
|
|
|
h.knowledgeRefs = append(h.knowledgeRefs, sr)
|
|
|
|
|
} else if refMap, ok := ref.(map[string]interface{}); ok {
|
|
|
|
|
// Parse from map if needed
|
|
|
|
|
searchResult := &types.SearchResult{
|
2026-03-26 08:45:51 +00:00
|
|
|
ID: getString(refMap, "id"),
|
|
|
|
|
Content: getString(refMap, "content"),
|
|
|
|
|
Score: getFloat64(refMap, "score"),
|
|
|
|
|
KnowledgeID: getString(refMap, "knowledge_id"),
|
|
|
|
|
KnowledgeTitle: getString(refMap, "knowledge_title"),
|
|
|
|
|
ChunkIndex: int(getFloat64(refMap, "chunk_index")),
|
|
|
|
|
KnowledgeDescription: getString(refMap, "knowledge_description"),
|
|
|
|
|
KnowledgeBaseID: getString(refMap, "knowledge_base_id"),
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if meta, ok := refMap["metadata"].(map[string]interface{}); ok {
|
|
|
|
|
metadata := make(map[string]string)
|
|
|
|
|
for k, v := range meta {
|
|
|
|
|
if strVal, ok := v.(string); ok {
|
|
|
|
|
metadata[k] = strVal
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
searchResult.Metadata = metadata
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h.knowledgeRefs = append(h.knowledgeRefs, searchResult)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update assistant message references
|
|
|
|
|
h.assistantMessage.KnowledgeReferences = h.knowledgeRefs
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Append references event to stream
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
2025-11-05 15:18:44 +00:00
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeReferences,
|
|
|
|
|
Content: "",
|
|
|
|
|
Done: false,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: map[string]interface{}{
|
2025-12-31 06:14:14 +00:00
|
|
|
"references": types.References(h.knowledgeRefs),
|
2025-11-05 15:18:44 +00:00
|
|
|
},
|
|
|
|
|
}); err != nil {
|
2025-11-07 14:41:41 +00:00
|
|
|
logger.GetLogger(h.ctx).Error("Append references event to stream failed", "error", err)
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleFinalAnswer handles final answer events
|
|
|
|
|
func (h *AgentStreamHandler) handleFinalAnswer(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.AgentFinalAnswerData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h.mu.Lock()
|
2026-06-03 18:35:54 +00:00
|
|
|
|
2025-11-12 06:27:00 +00:00
|
|
|
// Track start time on first chunk
|
|
|
|
|
if _, exists := h.eventStartTimes[evt.ID]; !exists {
|
|
|
|
|
h.eventStartTimes[evt.ID] = time.Now()
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 13:12:03 +00:00
|
|
|
// Emit a one-shot TTFB log the first time *any* answer chunk reaches
|
|
|
|
|
// the stream handler. This lets us compare the backend's "request in →
|
|
|
|
|
// first token out" timing against the frontend-observed TTFB and pin
|
|
|
|
|
// down where latency lives (network vs server vs LLM).
|
|
|
|
|
if !h.ttfbLogged && !h.receivedAt.IsZero() {
|
|
|
|
|
h.ttfbLogged = true
|
|
|
|
|
ttfb := time.Since(h.receivedAt)
|
|
|
|
|
logger.GetLogger(h.ctx).Infof("TTFB:first_answer_chunk request_id=%s, session_id=%s, ttfb_ms=%d",
|
|
|
|
|
h.requestID, h.sessionID, ttfb.Milliseconds())
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 18:35:54 +00:00
|
|
|
// Accumulate final answer locally for assistant message (database). Track
|
|
|
|
|
// per event ID so a later supersede can subtract this segment's content.
|
|
|
|
|
if data.Content != "" {
|
|
|
|
|
seg := h.findAnswerSegment(evt.ID)
|
|
|
|
|
if seg == nil {
|
|
|
|
|
seg = &answerSegment{id: evt.ID}
|
|
|
|
|
h.answerSegments = append(h.answerSegments, seg)
|
|
|
|
|
}
|
|
|
|
|
seg.content += data.Content
|
|
|
|
|
h.finalAnswer = h.composeFinalAnswer()
|
|
|
|
|
}
|
2026-03-04 13:32:19 +00:00
|
|
|
if data.IsFallback {
|
|
|
|
|
h.assistantMessage.IsFallback = true
|
|
|
|
|
}
|
2025-11-12 06:27:00 +00:00
|
|
|
|
|
|
|
|
// Calculate duration if done
|
|
|
|
|
var metadata map[string]interface{}
|
|
|
|
|
if data.Done {
|
|
|
|
|
startTime := h.eventStartTimes[evt.ID]
|
|
|
|
|
duration := time.Since(startTime)
|
|
|
|
|
metadata = map[string]interface{}{
|
|
|
|
|
"event_id": evt.ID,
|
|
|
|
|
"duration_ms": duration.Milliseconds(),
|
|
|
|
|
"completed_at": time.Now().Unix(),
|
|
|
|
|
}
|
|
|
|
|
delete(h.eventStartTimes, evt.ID)
|
|
|
|
|
} else {
|
|
|
|
|
metadata = map[string]interface{}{
|
|
|
|
|
"event_id": evt.ID,
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-04 13:32:19 +00:00
|
|
|
if data.IsFallback {
|
|
|
|
|
metadata["is_fallback"] = true
|
|
|
|
|
}
|
2025-11-05 15:18:44 +00:00
|
|
|
h.mu.Unlock()
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Append this chunk to stream (frontend will accumulate by event ID)
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeAnswer,
|
|
|
|
|
Content: data.Content, // Just this chunk
|
|
|
|
|
Done: data.Done,
|
|
|
|
|
Timestamp: time.Now(),
|
2025-11-12 06:27:00 +00:00
|
|
|
Data: metadata,
|
2025-11-07 14:41:41 +00:00
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Error("Append answer event to stream failed", "error", err)
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 15:18:44 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleReflection handles agent reflection events
|
|
|
|
|
func (h *AgentStreamHandler) handleReflection(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.AgentReflectionData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Append this chunk to stream (frontend will accumulate by event ID)
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeReflection,
|
|
|
|
|
Content: data.Content, // Just this chunk
|
|
|
|
|
Done: data.Done,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Error("Append reflection event to stream failed", "error", err)
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleError handles error events
|
|
|
|
|
func (h *AgentStreamHandler) handleError(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.ErrorData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Build error metadata
|
|
|
|
|
metadata := map[string]interface{}{
|
|
|
|
|
"stage": data.Stage,
|
|
|
|
|
"error": data.Error,
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Append error event to stream
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeError,
|
|
|
|
|
Content: data.Error,
|
|
|
|
|
Done: true,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: metadata,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Error("Append error event to stream failed", "error", err)
|
|
|
|
|
}
|
2025-11-05 15:18:44 +00:00
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// handleSessionTitle handles session title update events
|
|
|
|
|
func (h *AgentStreamHandler) handleSessionTitle(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.SessionTitleData)
|
2025-11-05 15:18:44 +00:00
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 14:17:56 +00:00
|
|
|
// Use background context for title event since it may arrive after stream completion
|
|
|
|
|
bgCtx := context.Background()
|
|
|
|
|
|
2025-11-07 14:41:41 +00:00
|
|
|
// Append title event to stream
|
2025-12-19 14:17:56 +00:00
|
|
|
if err := h.streamManager.AppendEvent(bgCtx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
2025-11-07 14:41:41 +00:00
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeSessionTitle,
|
|
|
|
|
Content: data.Title,
|
|
|
|
|
Done: true,
|
2025-11-05 15:18:44 +00:00
|
|
|
Timestamp: time.Now(),
|
2025-11-07 14:41:41 +00:00
|
|
|
Data: map[string]interface{}{
|
|
|
|
|
"session_id": data.SessionID,
|
|
|
|
|
"title": data.Title,
|
|
|
|
|
},
|
2025-11-05 15:18:44 +00:00
|
|
|
}); err != nil {
|
2025-12-19 14:17:56 +00:00
|
|
|
logger.GetLogger(h.ctx).Warn("Append session title event to stream failed (stream may have ended)", "error", err)
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
2025-11-07 14:41:41 +00:00
|
|
|
|
|
|
|
|
return nil
|
2025-11-05 15:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 16:58:26 +00:00
|
|
|
// handleComplete handles agent complete events
|
|
|
|
|
func (h *AgentStreamHandler) handleComplete(ctx context.Context, evt event.Event) error {
|
|
|
|
|
data, ok := evt.Data.(event.AgentCompleteData)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h.mu.Lock()
|
|
|
|
|
defer h.mu.Unlock()
|
|
|
|
|
|
|
|
|
|
// Update assistant message with final data
|
|
|
|
|
if data.MessageID == h.assistantMessageID {
|
|
|
|
|
// h.assistantMessage.Content = data.FinalAnswer
|
|
|
|
|
h.assistantMessage.IsCompleted = true
|
2026-03-06 04:21:23 +00:00
|
|
|
h.assistantMessage.AgentDurationMs = data.TotalDurationMs
|
2025-11-07 16:58:26 +00:00
|
|
|
|
|
|
|
|
// Update knowledge references if provided
|
|
|
|
|
if len(data.KnowledgeRefs) > 0 {
|
|
|
|
|
knowledgeRefs := make([]*types.SearchResult, 0, len(data.KnowledgeRefs))
|
|
|
|
|
for _, ref := range data.KnowledgeRefs {
|
|
|
|
|
if sr, ok := ref.(*types.SearchResult); ok {
|
|
|
|
|
knowledgeRefs = append(knowledgeRefs, sr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
h.assistantMessage.KnowledgeReferences = knowledgeRefs
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 04:21:23 +00:00
|
|
|
h.assistantMessage.Content += data.FinalAnswer
|
|
|
|
|
|
2025-11-07 16:58:26 +00:00
|
|
|
// Update agent steps if provided
|
|
|
|
|
if data.AgentSteps != nil {
|
|
|
|
|
if steps, ok := data.AgentSteps.([]types.AgentStep); ok {
|
2026-06-15 16:49:20 +00:00
|
|
|
h.assistantMessage.AgentSteps = agenttools.SanitizeAgentStepsForStorage(steps)
|
2025-11-07 16:58:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 09:21:13 +00:00
|
|
|
// Fallback: if no answer events were streamed but we have a final answer,
|
|
|
|
|
// emit it as answer events so the frontend can render it properly.
|
|
|
|
|
// This guards against edge cases where the LLM stops without calling final_answer.
|
|
|
|
|
if h.finalAnswer == "" && data.FinalAnswer != "" {
|
|
|
|
|
logger.GetLogger(h.ctx).Warnf(
|
2026-03-24 08:26:23 +00:00
|
|
|
"No answer events were streamed, emitting fallback answer (len=%d). "+
|
|
|
|
|
"This typically happens when: (1) model stopped naturally and content was sent as thought events, "+
|
|
|
|
|
"or (2) Ollama model returned tool calls non-incrementally. "+
|
|
|
|
|
"total_steps=%d, total_duration_ms=%d",
|
|
|
|
|
len(data.FinalAnswer), data.TotalSteps, data.TotalDurationMs,
|
2026-03-19 09:21:13 +00:00
|
|
|
)
|
|
|
|
|
fallbackID := fmt.Sprintf("answer-fallback-%d", time.Now().UnixMilli())
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: fallbackID,
|
|
|
|
|
Type: types.ResponseTypeAnswer,
|
|
|
|
|
Content: data.FinalAnswer,
|
|
|
|
|
Done: false,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
|
"event_id": fallbackID,
|
|
|
|
|
"is_fallback": true,
|
|
|
|
|
},
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Errorf("Append fallback answer event failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: fallbackID,
|
|
|
|
|
Type: types.ResponseTypeAnswer,
|
|
|
|
|
Content: "",
|
|
|
|
|
Done: true,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
|
"event_id": fallbackID,
|
|
|
|
|
"is_fallback": true,
|
|
|
|
|
},
|
|
|
|
|
}); err != nil {
|
|
|
|
|
logger.GetLogger(h.ctx).Errorf("Append fallback answer done event failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 16:58:26 +00:00
|
|
|
// Send completion event to stream manager so SSE can detect completion
|
|
|
|
|
if err := h.streamManager.AppendEvent(h.ctx, h.sessionID, h.assistantMessageID, interfaces.StreamEvent{
|
|
|
|
|
ID: evt.ID,
|
|
|
|
|
Type: types.ResponseTypeComplete,
|
|
|
|
|
Content: "",
|
|
|
|
|
Done: true,
|
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
|
Data: map[string]interface{}{
|
2025-11-11 17:18:12 +00:00
|
|
|
"total_steps": data.TotalSteps,
|
|
|
|
|
"total_duration_ms": data.TotalDurationMs,
|
2025-11-07 16:58:26 +00:00
|
|
|
},
|
|
|
|
|
}); err != nil {
|
2025-11-18 15:18:43 +00:00
|
|
|
logger.GetLogger(h.ctx).Errorf("Append complete event to stream failed: %v", err)
|
2025-11-07 16:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|