mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Introduce Beeper AI stream handling
Add support for Beeper AI stream events by introducing BeeperAIStreamEventContent and updating the event type mapping. Rename the action-response network API and types to BeeperAIStream (BeeperAIStreamHandlingNetworkAPI, HandleMatrixBeeperAIStream, MatrixBeeperAIStream) and update the error constant to ErrBeeperAIStreamNotSupported. Remove legacy Beeper action response handling and registration, and wire the portal to dispatch AI stream events to the new network API with appropriate content validation and error handling.
This commit is contained in:
parent
dbd5a393e6
commit
4d03efd33a
6 changed files with 34 additions and 41 deletions
|
|
@ -75,7 +75,7 @@ var (
|
|||
ErrMediaConvertFailed error = WrapErrorInStatus(errors.New("failed to convert media")).WithMessage("failed to convert media").WithIsCertain(true).WithSendNotice(true)
|
||||
ErrMembershipNotSupported error = WrapErrorInStatus(errors.New("this bridge does not support changing group membership")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
|
||||
ErrDeleteChatNotSupported error = WrapErrorInStatus(errors.New("this bridge does not support deleting chats")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
|
||||
ErrBeeperActionResponseNotSupported error = WrapErrorInStatus(errors.New("this bridge does not support Beeper action responses")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
|
||||
ErrBeeperAIStreamNotSupported error = WrapErrorInStatus(errors.New("this bridge does not support Beeper AI stream events")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
|
||||
ErrPowerLevelsNotSupported error = WrapErrorInStatus(errors.New("this bridge does not support changing group power levels")).WithIsCertain(true).WithErrorAsMessage().WithSendNotice(false).WithErrorReason(event.MessageStatusUnsupported)
|
||||
ErrRemoteEchoTimeout = WrapErrorInStatus(errors.New("remote echo timed out")).WithIsCertain(false).WithSendNotice(true).WithErrorReason(event.MessageStatusTooOld)
|
||||
ErrRemoteAckTimeout = WrapErrorInStatus(errors.New("remote ack timed out")).WithIsCertain(false).WithSendNotice(true).WithErrorReason(event.MessageStatusTooOld)
|
||||
|
|
|
|||
|
|
@ -155,7 +155,6 @@ func (br *Connector) Init(bridge *bridgev2.Bridge) {
|
|||
br.EventProcessor.On(event.StateBeeperDisappearingTimer, br.handleRoomEvent)
|
||||
br.EventProcessor.On(event.BeeperDeleteChat, br.handleRoomEvent)
|
||||
br.EventProcessor.On(event.BeeperAcceptMessageRequest, br.handleRoomEvent)
|
||||
br.EventProcessor.On(event.BeeperActionResponse, br.handleRoomEvent)
|
||||
br.EventProcessor.On(event.EphemeralEventReceipt, br.handleEphemeralEvent)
|
||||
br.EventProcessor.On(event.EphemeralEventTyping, br.handleEphemeralEvent)
|
||||
br.EventProcessor.On(event.BeeperEphemeralEventAIStream, br.handleEphemeralEvent)
|
||||
|
|
|
|||
|
|
@ -726,12 +726,9 @@ type MessageRequestAcceptingNetworkAPI interface {
|
|||
HandleMatrixAcceptMessageRequest(ctx context.Context, msg *MatrixAcceptMessageRequest) error
|
||||
}
|
||||
|
||||
// BeeperActionResponseHandlingNetworkAPI is an optional interface that network connectors
|
||||
// can implement to handle com.beeper.action_response events (MSC1485 action hints).
|
||||
type BeeperActionResponseHandlingNetworkAPI interface {
|
||||
type BeeperAIStreamHandlingNetworkAPI interface {
|
||||
NetworkAPI
|
||||
// HandleMatrixBeeperActionResponse is called when a user clicks an action hint button.
|
||||
HandleMatrixBeeperActionResponse(ctx context.Context, msg *MatrixBeeperActionResponse) error
|
||||
HandleMatrixBeeperAIStream(ctx context.Context, msg *MatrixBeeperAIStream) error
|
||||
}
|
||||
|
||||
type ResolveIdentifierResponse struct {
|
||||
|
|
@ -1447,7 +1444,7 @@ type MatrixViewingChat struct {
|
|||
|
||||
type MatrixDeleteChat = MatrixEventBase[*event.BeeperChatDeleteEventContent]
|
||||
type MatrixAcceptMessageRequest = MatrixEventBase[*event.BeeperAcceptMessageRequestEventContent]
|
||||
type MatrixBeeperActionResponse = MatrixEventBase[*event.BeeperActionResponseEventContent]
|
||||
type MatrixBeeperAIStream = MatrixEventBase[*event.BeeperAIStreamEventContent]
|
||||
type MatrixMarkedUnread = MatrixRoomMeta[*event.MarkedUnreadEventContent]
|
||||
type MatrixMute = MatrixRoomMeta[*event.BeeperMuteEventContent]
|
||||
type MatrixRoomTag = MatrixRoomMeta[*event.TagEventContent]
|
||||
|
|
|
|||
|
|
@ -820,8 +820,6 @@ func (portal *Portal) handleMatrixEvent(ctx context.Context, sender *User, evt *
|
|||
return portal.handleMatrixDeleteChat(ctx, login, origSender, evt)
|
||||
case event.BeeperAcceptMessageRequest:
|
||||
return portal.handleMatrixAcceptMessageRequest(ctx, login, origSender, evt)
|
||||
case event.BeeperActionResponse:
|
||||
return portal.handleMatrixBeeperActionResponse(ctx, login, origSender, evt)
|
||||
default:
|
||||
return EventHandlingResultIgnored
|
||||
}
|
||||
|
|
@ -967,7 +965,26 @@ func (portal *Portal) handleMatrixAIStream(ctx context.Context, sender *User, ev
|
|||
UserID: sender.MXID,
|
||||
}
|
||||
}
|
||||
return portal.handleMatrixBeeperActionResponse(ctx, login, origSender, evt)
|
||||
content, ok := evt.Content.Parsed.(*event.BeeperAIStreamEventContent)
|
||||
if !ok {
|
||||
log.Error().Type("content_type", evt.Content.Parsed).Msg("Unexpected parsed content type")
|
||||
return EventHandlingResultFailed.WithMSSError(fmt.Errorf("%w: %T", ErrUnexpectedParsedContentType, evt.Content.Parsed))
|
||||
}
|
||||
api, ok := login.Client.(BeeperAIStreamHandlingNetworkAPI)
|
||||
if !ok {
|
||||
return EventHandlingResultIgnored.WithMSSError(ErrBeeperAIStreamNotSupported)
|
||||
}
|
||||
err = api.HandleMatrixBeeperAIStream(ctx, &MatrixBeeperAIStream{
|
||||
Event: evt,
|
||||
Content: content,
|
||||
Portal: portal,
|
||||
OrigSender: origSender,
|
||||
})
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to handle Matrix AI stream event")
|
||||
return EventHandlingResultFailed.WithMSSError(err)
|
||||
}
|
||||
return EventHandlingResultSuccess.WithMSS()
|
||||
}
|
||||
|
||||
func (portal *Portal) sendTypings(ctx context.Context, userIDs []id.UserID, typing bool) {
|
||||
|
|
@ -1847,35 +1864,6 @@ func (portal *Portal) handleMatrixAcceptMessageRequest(
|
|||
return EventHandlingResultSuccess.WithMSS()
|
||||
}
|
||||
|
||||
func (portal *Portal) handleMatrixBeeperActionResponse(
|
||||
ctx context.Context,
|
||||
sender *UserLogin,
|
||||
origSender *OrigSender,
|
||||
evt *event.Event,
|
||||
) EventHandlingResult {
|
||||
log := zerolog.Ctx(ctx)
|
||||
content, ok := evt.Content.Parsed.(*event.BeeperActionResponseEventContent)
|
||||
if !ok {
|
||||
log.Error().Type("content_type", evt.Content.Parsed).Msg("Unexpected parsed content type")
|
||||
return EventHandlingResultFailed.WithMSSError(fmt.Errorf("%w: %T", ErrUnexpectedParsedContentType, evt.Content.Parsed))
|
||||
}
|
||||
api, ok := sender.Client.(BeeperActionResponseHandlingNetworkAPI)
|
||||
if !ok {
|
||||
return EventHandlingResultIgnored.WithMSSError(ErrBeeperActionResponseNotSupported)
|
||||
}
|
||||
err := api.HandleMatrixBeeperActionResponse(ctx, &MatrixBeeperActionResponse{
|
||||
Event: evt,
|
||||
Content: content,
|
||||
Portal: portal,
|
||||
OrigSender: origSender,
|
||||
})
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to handle Matrix action response")
|
||||
return EventHandlingResultFailed.WithMSSError(err)
|
||||
}
|
||||
return EventHandlingResultSuccess.WithMSS()
|
||||
}
|
||||
|
||||
func (portal *Portal) autoAcceptMessageRequest(
|
||||
ctx context.Context, evt *event.Event, sender *UserLogin, origSender *OrigSender, caps *event.RoomFeatures,
|
||||
) error {
|
||||
|
|
|
|||
|
|
@ -237,6 +237,15 @@ type BeeperActionResponseEventContent struct {
|
|||
Context json.RawMessage `json:"context,omitempty"`
|
||||
}
|
||||
|
||||
type BeeperAIStreamEventContent struct {
|
||||
TurnID string `json:"turn_id"`
|
||||
Seq int `json:"seq"`
|
||||
Part map[string]any `json:"part"`
|
||||
TargetEvent id.EventID `json:"target_event,omitempty"`
|
||||
AgentID string `json:"agent_id,omitempty"`
|
||||
RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
|
||||
}
|
||||
|
||||
func (content *BeeperActionResponseEventContent) GetRelatesTo() *RelatesTo {
|
||||
if content.RelatesTo == nil {
|
||||
content.RelatesTo = &RelatesTo{}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ var TypeMap = map[Type]reflect.Type{
|
|||
EphemeralEventTyping: reflect.TypeOf(TypingEventContent{}),
|
||||
EphemeralEventReceipt: reflect.TypeOf(ReceiptEventContent{}),
|
||||
EphemeralEventPresence: reflect.TypeOf(PresenceEventContent{}),
|
||||
BeeperEphemeralEventAIStream: reflect.TypeOf(BeeperActionResponseEventContent{}),
|
||||
BeeperEphemeralEventAIStream: reflect.TypeOf(BeeperAIStreamEventContent{}),
|
||||
|
||||
InRoomVerificationReady: reflect.TypeOf(VerificationReadyEventContent{}),
|
||||
InRoomVerificationStart: reflect.TypeOf(VerificationStartEventContent{}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue