mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
8caf9aeb2b
Migrate hook observation to runtime events and update the process hook notification protocol. Add runtime event publication for message bus failures, channel lifecycle/outbound flow, gateway reloads, MCP server state, and MCP tool calls. Validation: go test ./pkg/events/... ./pkg/bus ./pkg/agent ./pkg/channels ./pkg/mcp ./pkg/tools/integration ./pkg/gateway; make lint
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/agent"
|
|
runtimeevents "github.com/sipeed/picoclaw/pkg/events"
|
|
)
|
|
|
|
const gatewayEventPublishTimeout = 100 * time.Millisecond
|
|
|
|
type gatewayReloadPayload struct {
|
|
DurationMS int64 `json:"duration_ms,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
func publishGatewayReloadEvent(
|
|
al *agent.AgentLoop,
|
|
kind runtimeevents.Kind,
|
|
startedAt time.Time,
|
|
err error,
|
|
) {
|
|
if al == nil || al.RuntimeEventBus() == nil {
|
|
return
|
|
}
|
|
|
|
severity := runtimeevents.SeverityInfo
|
|
payload := gatewayReloadPayload{}
|
|
if !startedAt.IsZero() {
|
|
payload.DurationMS = time.Since(startedAt).Milliseconds()
|
|
}
|
|
if err != nil {
|
|
severity = runtimeevents.SeverityError
|
|
payload.Error = err.Error()
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), gatewayEventPublishTimeout)
|
|
defer cancel()
|
|
al.RuntimeEventBus().Publish(ctx, runtimeevents.Event{
|
|
Kind: kind,
|
|
Source: runtimeevents.Source{Component: "gateway"},
|
|
Severity: severity,
|
|
Payload: payload,
|
|
})
|
|
}
|