+86
-44
@@ -24,40 +24,45 @@ import (
|
||||
)
|
||||
|
||||
type RouterOptions struct {
|
||||
ServiceName string
|
||||
Logger *slog.Logger
|
||||
RateLimiter RateLimiter
|
||||
Readiness *health.Checker
|
||||
TokenVerifier *identity.OIDCVerifier
|
||||
IdentityRepository *identity.Repository
|
||||
SaaSService *saas.Service
|
||||
DeviceVerifier DeviceRequestVerifier
|
||||
DeviceService *device.Repository
|
||||
DeviceTelemetrySubmitter DeviceTelemetrySubmitter
|
||||
MediaService *media.Service
|
||||
WebEventService *webevents.Service
|
||||
SharingService *sharing.Service
|
||||
OpsConfigService *opsconfig.Service
|
||||
BillingService *billing.Service
|
||||
AlertService *alerts.Service
|
||||
DiagnosticService *diagnostics.Service
|
||||
OpsAccessService *opsaccess.Service
|
||||
OpsDeviceService *opsdevice.Service
|
||||
ContentModelService *contentmodel.Service
|
||||
ConversationCreator ConversationCreator
|
||||
ConversationActivator ConversationActivator
|
||||
DeviceConversationStateReader DeviceConversationStateReader
|
||||
ConversationHeartbeater ConversationHeartbeater
|
||||
ConversationStopper ConversationStopper
|
||||
ConversationTranscriptSubmitter ConversationTranscriptSubmitter
|
||||
ProviderCallbackSecret []byte
|
||||
ProviderCallbackSkew time.Duration
|
||||
ProviderCallbackProcessor ProviderCallbackProcessor
|
||||
PlatformHealthCallbackSecret []byte
|
||||
PlatformHealthCallbackSkew time.Duration
|
||||
PlatformHealthProcessor PlatformHealthProcessor
|
||||
MemoryToolService *memorytool.Service
|
||||
MemoryToolSigner *memorytool.TokenSigner
|
||||
ServiceName string
|
||||
Logger *slog.Logger
|
||||
RateLimiter RateLimiter
|
||||
Readiness *health.Checker
|
||||
TokenVerifier *identity.OIDCVerifier
|
||||
IdentityRepository *identity.Repository
|
||||
SaaSService *saas.Service
|
||||
DeviceVerifier DeviceRequestVerifier
|
||||
DeviceService *device.Repository
|
||||
DeviceTelemetrySubmitter DeviceTelemetrySubmitter
|
||||
MediaService *media.Service
|
||||
WebEventService *webevents.Service
|
||||
SharingService *sharing.Service
|
||||
OpsConfigService *opsconfig.Service
|
||||
BillingService *billing.Service
|
||||
AlertService *alerts.Service
|
||||
DiagnosticService *diagnostics.Service
|
||||
OpsAccessService *opsaccess.Service
|
||||
OpsDeviceService *opsdevice.Service
|
||||
ContentModelService *contentmodel.Service
|
||||
ConversationCreator ConversationCreator
|
||||
ConversationActivator ConversationActivator
|
||||
DeviceConversationStateReader DeviceConversationStateReader
|
||||
ConversationHeartbeater ConversationHeartbeater
|
||||
ConversationStopper ConversationStopper
|
||||
ConversationTranscriptSubmitter ConversationTranscriptSubmitter
|
||||
HardwareAgentSessionService HardwareAgentSessionService
|
||||
HardwareAgentProvisioningService HardwareAgentProvisioningService
|
||||
DeviceFactoryResetService DeviceFactoryResetService
|
||||
ProviderCallbackSecret []byte
|
||||
ProviderCallbackSkew time.Duration
|
||||
ProviderCallbackProcessor ProviderCallbackProcessor
|
||||
NativeSubtitleSecret []byte
|
||||
NativeSubtitleProcessor NativeSubtitleProcessor
|
||||
PlatformHealthCallbackSecret []byte
|
||||
PlatformHealthCallbackSkew time.Duration
|
||||
PlatformHealthProcessor PlatformHealthProcessor
|
||||
MemoryToolService *memorytool.Service
|
||||
MemoryToolSigner *memorytool.TokenSigner
|
||||
}
|
||||
|
||||
func NewRouter(options RouterOptions) http.Handler {
|
||||
@@ -165,6 +170,8 @@ func NewRouter(options RouterOptions) http.Handler {
|
||||
mux.Handle("DELETE /api/v1/ops/devices/{id}", authenticated(DeleteOpsDeviceHandler(options.OpsDeviceService)))
|
||||
mux.Handle("POST /api/v1/ops/devices/{id}/credentials/rotate", authenticated(RotateOpsDeviceCredentialHandler(options.OpsDeviceService)))
|
||||
mux.Handle("POST /api/v1/ops/devices/{id}/claims", authenticated(IssueOpsDeviceClaimHandler(options.OpsDeviceService)))
|
||||
mux.Handle("POST /api/v1/ops/devices/{id}/activation-transitions", authenticated(TransitionOpsDeviceActivationHandler(options.OpsDeviceService)))
|
||||
mux.Handle("GET /api/v1/ops/devices/{id}/activation-transitions", authenticated(ListOpsDeviceActivationTransitionsHandler(options.OpsDeviceService)))
|
||||
}
|
||||
if options.ContentModelService != nil {
|
||||
mux.Handle("GET /api/v1/content-models", authenticated(ListContentModelsHandler(options.ContentModelService)))
|
||||
@@ -223,6 +230,21 @@ func NewRouter(options RouterOptions) http.Handler {
|
||||
mux.Handle("GET /api/v1/firmware-rollouts/{id}", authenticated(GetFirmwareRolloutHandler(options.SaaSService)))
|
||||
mux.Handle("POST /api/v1/firmware-rollouts/{id}/pause", authenticated(PauseFirmwareRolloutHandler(options.SaaSService)))
|
||||
mux.Handle("POST /api/v1/firmware-rollouts/{id}/rollback", authenticated(RollbackFirmwareRolloutHandler(options.SaaSService)))
|
||||
mux.Handle("GET /api/v1/ops/firmware-signing-keys", authenticated(ListOpsFirmwareSigningKeysHandler(options.SaaSService)))
|
||||
mux.Handle("POST /api/v1/ops/firmware-signing-keys", authenticated(RegisterOpsFirmwareSigningKeyHandler(options.SaaSService)))
|
||||
mux.Handle("POST /api/v1/ops/firmware-signing-keys/revoke", authenticated(RevokeOpsFirmwareSigningKeyHandler(options.SaaSService)))
|
||||
mux.Handle("GET /api/v1/ops/firmware-releases", authenticated(ListOpsFirmwareReleasesHandler(options.SaaSService)))
|
||||
mux.Handle("POST /api/v1/ops/firmware-releases", authenticated(PrepareOpsFirmwareReleaseHandler(options.SaaSService)))
|
||||
mux.Handle("POST /api/v1/ops/firmware-releases/{id}/upload-session", authenticated(OpsFirmwareReleaseActionHandler(options.SaaSService, "upload-session")))
|
||||
mux.Handle("POST /api/v1/ops/firmware-releases/{id}/finalize", authenticated(OpsFirmwareReleaseActionHandler(options.SaaSService, "finalize")))
|
||||
mux.Handle("POST /api/v1/ops/firmware-releases/{id}/pause", authenticated(OpsFirmwareReleaseActionHandler(options.SaaSService, "pause")))
|
||||
mux.Handle("POST /api/v1/ops/firmware-releases/{id}/resume", authenticated(OpsFirmwareReleaseActionHandler(options.SaaSService, "resume")))
|
||||
mux.Handle("POST /api/v1/ops/firmware-releases/{id}/retire", authenticated(OpsFirmwareReleaseActionHandler(options.SaaSService, "retire")))
|
||||
mux.Handle("GET /api/v1/ops/firmware-releases/{id}/download", authenticated(DownloadOpsFirmwareReleaseHandler(options.SaaSService)))
|
||||
mux.Handle("GET /api/v1/ops/firmware-rollouts", authenticated(ListOpsFirmwareRolloutsHandler(options.SaaSService)))
|
||||
mux.Handle("POST /api/v1/ops/firmware-rollouts", authenticated(StartOpsFirmwareRolloutHandler(options.SaaSService)))
|
||||
mux.Handle("GET /api/v1/ops/firmware-rollouts/{id}", authenticated(GetOpsFirmwareRolloutHandler(options.SaaSService)))
|
||||
mux.Handle("POST /api/v1/ops/firmware-rollouts/{id}/pause", authenticated(PauseOpsFirmwareRolloutHandler(options.SaaSService)))
|
||||
mux.Handle("GET /api/v1/subjects/{id}/conversations", authenticated(ListSubjectConversationsHandler(options.SaaSService)))
|
||||
mux.Handle("GET /api/v1/conversations/{id}", authenticated(GetConversationHandler(options.SaaSService)))
|
||||
mux.Handle("GET /api/v1/conversations/{id}/usage", authenticated(GetConversationUsageHandler(options.SaaSService)))
|
||||
@@ -277,6 +299,12 @@ func NewRouter(options RouterOptions) http.Handler {
|
||||
deviceAuthenticated := func(handler http.Handler) http.Handler {
|
||||
return DeviceAuth(options.DeviceVerifier, DeviceRateLimit(logger, options.RateLimiter, handler))
|
||||
}
|
||||
activeDevice := func(handler http.Handler) http.Handler {
|
||||
return deviceAuthenticated(RequireDeviceActivation([]string{"ACTIVE"}, handler))
|
||||
}
|
||||
provisionableDevice := func(handler http.Handler) http.Handler {
|
||||
return deviceAuthenticated(RequireDeviceActivation([]string{"BOUND", "PROVISIONING", "ACTIVE"}, handler))
|
||||
}
|
||||
mux.Handle("GET /device/v2/bootstrap", deviceAuthenticated(DeviceBootstrapHandler(options.DeviceService)))
|
||||
mux.Handle("GET /device/v2/config", deviceAuthenticated(DeviceConfigHandler(options.DeviceService)))
|
||||
mux.Handle("GET /device/v2/commands", deviceAuthenticated(PullDeviceCommandsHandler(options.DeviceService)))
|
||||
@@ -285,32 +313,46 @@ func NewRouter(options RouterOptions) http.Handler {
|
||||
mux.Handle("POST /device/v2/telemetry:batch", deviceAuthenticated(SubmitDeviceTelemetryHandler(options.DeviceTelemetrySubmitter)))
|
||||
}
|
||||
mux.Handle("GET /device/v2/firmware-releases/{id}/download", deviceAuthenticated(DeviceFirmwareDownloadHandler(options.SaaSService)))
|
||||
if options.DeviceFactoryResetService != nil {
|
||||
mux.Handle("POST /device/v3/factory-reset", deviceAuthenticated(DeviceFactoryResetHandler(options.DeviceFactoryResetService)))
|
||||
}
|
||||
if options.MediaService != nil {
|
||||
mux.Handle("POST /device/v2/conversations/{id}/upload-batches", deviceAuthenticated(PrepareMediaUploadBatchHandler(options.MediaService)))
|
||||
mux.Handle("POST /device/v2/upload-batches/{id}/complete", deviceAuthenticated(CompleteMediaUploadBatchHandler(options.MediaService)))
|
||||
mux.Handle("GET /device/v2/upload-batches/{id}", deviceAuthenticated(GetDeviceMediaUploadBatchHandler(options.MediaService)))
|
||||
mux.Handle("POST /device/v2/media-segments/{id}/local-delete-ack", deviceAuthenticated(AcknowledgeLocalMediaDeleteHandler(options.MediaService)))
|
||||
mux.Handle("POST /device/v2/conversations/{id}/upload-batches", activeDevice(PrepareMediaUploadBatchHandler(options.MediaService)))
|
||||
mux.Handle("POST /device/v2/upload-batches/{id}/complete", activeDevice(CompleteMediaUploadBatchHandler(options.MediaService)))
|
||||
mux.Handle("GET /device/v2/upload-batches/{id}", activeDevice(GetDeviceMediaUploadBatchHandler(options.MediaService)))
|
||||
mux.Handle("POST /device/v2/media-segments/{id}/local-delete-ack", activeDevice(AcknowledgeLocalMediaDeleteHandler(options.MediaService)))
|
||||
}
|
||||
if options.ConversationCreator != nil {
|
||||
mux.Handle("POST /device/v2/conversations", deviceAuthenticated(CreateConversationHandler(options.ConversationCreator)))
|
||||
mux.Handle("POST /device/v2/conversations", activeDevice(CreateConversationHandler(options.ConversationCreator)))
|
||||
}
|
||||
if options.ConversationActivator != nil {
|
||||
mux.Handle("POST /device/v2/conversations/{id}/activate", deviceAuthenticated(ActivateConversationHandler(options.ConversationActivator)))
|
||||
mux.Handle("POST /device/v2/conversations/{id}/activate", activeDevice(ActivateConversationHandler(options.ConversationActivator)))
|
||||
}
|
||||
if options.DeviceConversationStateReader != nil {
|
||||
mux.Handle("GET /device/v2/conversations/{id}", deviceAuthenticated(GetDeviceConversationStateHandler(options.DeviceConversationStateReader)))
|
||||
mux.Handle("GET /device/v2/conversations/{id}", activeDevice(GetDeviceConversationStateHandler(options.DeviceConversationStateReader)))
|
||||
}
|
||||
if options.ConversationHeartbeater != nil {
|
||||
mux.Handle("POST /device/v2/conversations/{id}/heartbeat", deviceAuthenticated(HeartbeatConversationHandler(options.ConversationHeartbeater)))
|
||||
mux.Handle("POST /device/v2/conversations/{id}/heartbeat", activeDevice(HeartbeatConversationHandler(options.ConversationHeartbeater)))
|
||||
}
|
||||
if options.ConversationStopper != nil {
|
||||
mux.Handle("POST /device/v2/conversations/{id}/stop", deviceAuthenticated(StopConversationHandler(options.ConversationStopper)))
|
||||
mux.Handle("POST /device/v2/conversations/{id}/stop", activeDevice(StopConversationHandler(options.ConversationStopper)))
|
||||
}
|
||||
if options.ConversationTranscriptSubmitter != nil {
|
||||
mux.Handle("POST /device/v2/conversations/{id}/turns:batch", deviceAuthenticated(SubmitConversationTurnsHandler(options.ConversationTranscriptSubmitter)))
|
||||
mux.Handle("POST /device/v2/conversations/{id}/turns:batch", activeDevice(SubmitConversationTurnsHandler(options.ConversationTranscriptSubmitter)))
|
||||
}
|
||||
if options.HardwareAgentSessionService != nil {
|
||||
if options.HardwareAgentProvisioningService != nil {
|
||||
mux.Handle("POST /device/v3/hardware-agent-credentials:provision", provisionableDevice(ProvisionHardwareAgentCredentialHandler(options.HardwareAgentProvisioningService)))
|
||||
}
|
||||
mux.Handle("POST /device/v3/agent-sessions", activeDevice(CreateHardwareAgentSessionHandler(options.HardwareAgentSessionService)))
|
||||
mux.Handle("POST /device/v3/agent-sessions/{id}/events", activeDevice(HardwareAgentEventHandler(options.HardwareAgentSessionService)))
|
||||
mux.Handle("POST /device/v3/agent-sessions/{id}/turns:batch", activeDevice(SubmitConversationTurnsHandler(options.ConversationTranscriptSubmitter)))
|
||||
}
|
||||
}
|
||||
if options.ServiceName == "callbacks" && len(options.ProviderCallbackSecret) > 0 && options.ProviderCallbackProcessor != nil {
|
||||
if len(options.NativeSubtitleSecret) >= 32 && options.NativeSubtitleProcessor != nil {
|
||||
mux.Handle("POST /callbacks/v1/volcengine/subtitles", NativeSubtitleCallbackHandler(options.NativeSubtitleSecret, options.NativeSubtitleProcessor))
|
||||
}
|
||||
mux.Handle("POST /callbacks/v1/vertc/voice-chat", VoiceProviderCallbackHandler(
|
||||
options.ProviderCallbackSecret, options.ProviderCallbackSkew, options.ProviderCallbackProcessor,
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user