This commit is contained in:
2026-06-09 21:19:30 +08:00
parent 8b41ff9360
commit 0484e79978
66 changed files with 4043 additions and 533 deletions
+13 -3
View File
@@ -29,8 +29,8 @@ import (
// EventEnvelope 是推到 WS 的事件结构(与落库的 Event 字段同步,但带 ID 数值化方便 JSON)。
type EventEnvelope struct {
ID int64 `json:"id"`
Direction string `json:"direction"` // 'in' | 'out'
Kind string `json:"kind"` // 'request'|'response'|'notification'|'error'|'session_terminated'|'slow_consumer_disconnect'
Direction string `json:"direction"` // 'in' | 'out'
Kind string `json:"kind"` // 'request'|'response'|'notification'|'error'|'session_terminated'|'slow_consumer_disconnect'
Method string `json:"method,omitempty"`
Payload json.RawMessage `json:"payload"`
Truncated bool `json:"truncated"`
@@ -182,6 +182,16 @@ func (r *Relay) Close(status string, exitCode *int32) {
close(r.done)
}
// FanoutControl 把一条控制类 envelope(如 permission_request/permission_resolved)
// 推给所有 WS 订阅者。这类帧不落 acp_events、ID 恒为 0,由 PermissionService 调用。
// relay 已关闭时静默丢弃,避免向已关 channel 写入。
func (r *Relay) FanoutControl(env *EventEnvelope) {
if r.closed.Load() {
return
}
r.fanout(env)
}
// Done returns a channel closed when Relay is terminated.
func (r *Relay) Done() <-chan struct{} { return r.done }
@@ -249,7 +259,7 @@ func (r *Relay) handleAgentRequest(ctx context.Context, sess handlers.SessionCon
out := r.fsHandler.Write.Handle(ctx, sess, req.Params)
resp = r.fsResultToResponse(req.ID, out)
case "session/request_permission":
out := r.permHandler.Handle(ctx, sess, req.Params)
out := r.permHandler.Handle(ctx, sess, string(req.ID), req.Params)
resp = r.fsResultToResponse(req.ID, out)
default:
resp = NewResponseErr(req.ID, JSONRPCMethodNotFound, "method not implemented: "+req.Method)