Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

63 lines
2.3 KiB
Go

// Package eventstream is the tutti workspace binding of the catalog-agnostic
// event-stream registry (github.com/tutti-os/tutti/packages/events/stream-go).
//
// The pub/sub registry, scope routing and session fan-out live in stream-go.
// This package only fixes the scope axis to the workspace (EventScope) and keeps
// the tutti catalog (TopicDefinition / StaticCatalog / DefaultCatalog + payload
// validators). The aliases below preserve the original public surface so existing
// callers (daemon_events.go, wiring.go, tests) are unchanged.
package eventstream
import (
"strings"
streamgo "github.com/tutti-os/tutti/packages/events/stream-go"
)
// EventScope is the workspace scope axis used to route events.
type EventScope struct {
WorkspaceID string
}
// Re-exported core types, instantiated with the workspace scope.
type (
Service = streamgo.Service[EventScope]
Session = streamgo.Session[EventScope]
PublishedEvent = streamgo.PublishedEvent[EventScope]
ClientEvent = streamgo.ClientEvent
IntentHandler = streamgo.IntentHandler
Direction = streamgo.Direction
ValidationCode = streamgo.ValidationCode
ValidationError = streamgo.ValidationError
)
const (
DirectionClientToServer = streamgo.DirectionClientToServer
DirectionServerToClient = streamgo.DirectionServerToClient
ValidationCodeInvalidDirection = streamgo.ValidationCodeInvalidDirection
ValidationCodeInvalidPayload = streamgo.ValidationCodeInvalidPayload
ValidationCodeInvalidTopic = streamgo.ValidationCodeInvalidTopic
)
// NewService builds a workspace-scoped registry over the tutti catalog.
func NewService(catalog Catalog, handlers map[string]IntentHandler) *Service {
if catalog == nil {
catalog = DefaultCatalog()
}
return streamgo.NewService[EventScope](catalog, handlers, normalizeWorkspaceScope)
}
// normalizeWorkspaceScope trims the workspaceId and rejects whitespace-only ids.
func normalizeWorkspaceScope(scope EventScope) (EventScope, error) {
workspaceID := strings.TrimSpace(scope.WorkspaceID)
if scope.WorkspaceID != "" && workspaceID == "" {
return EventScope{}, &streamgo.ValidationError{
Code: streamgo.ValidationCodeInvalidPayload,
Message: "scope.workspaceId must not be empty",
}
}
return EventScope{WorkspaceID: workspaceID}, nil
}