Repository: emcie-co/parlant
File: server/src/emcie/server/api/sessions.py (Python)

Code before:
                interactions.append(
                    InteractionDTO(
                        kind="message",
                        source=e.source,
                        correlation_id=correlation_id,
                        data=cast(MessageEventData, e.data)["message"],
                        tool_calls=[
                            ToolCallDTO(
                                tool_name=tc["tool_name"],
                                arguments=tc["arguments"],
                                result=ToolResultDTO(
                                    data=tc["result"]["data"],
                                    metadata=tc["result"]["metadata"],
                                ),
                            )
                            for tc in tool_calls
                        ],
                    )
                )

        return ListInteractionsResponse(
            session_id=session_id,
            interactions=interactions,
        )

    @router.delete("/{session_id}/events/{min_offset}")
    async def delete_event(
        session_id: SessionId,
        min_offset: int,
    ) -> DeleteEventResponse:
        events = await session_store.list_events(
            session_id=session_id,
            min_offset=min_offset,
            exclude_deleted=True,
        )

        deleted_event_ids = [await session_store.delete_event(e.id) for e in events]

        return DeleteEventResponse(event_ids=[id for id in deleted_event_ids if id is not None])

    return router


Review comment (suggestion):
Not correct to have `/{min_offset}` as it suggests you are accessing the event called `{min_offset}` and deleting it. In practice, you are looking at all events using a filter (min offset) and deleting all of them. This should then be done using a query parameter, i.e., `DELETE /{session_id}/events?min_offset=N`

Code after:
                interactions.append(
                    InteractionDTO(
                        kind="message",
                        source=e.source,
                        correlation_id=correlation_id,
                        data=cast(MessageEventData, e.data)["message"],
                        tool_calls=[
                            ToolCallDTO(
                                tool_name=tc["tool_name"],
                                arguments=tc["arguments"],
                                result=ToolResultDTO(
                                    data=tc["result"]["data"],
                                    metadata=tc["result"]["metadata"],
                                ),
                            )
                            for tc in tool_calls
                        ],
                    )
                )

        return ListInteractionsResponse(
            session_id=session_id,
            interactions=interactions,
        )

    @router.delete("/{session_id}/events")
    async def delete_events(
        session_id: SessionId,
        min_offset: int,
    ) -> DeleteEventsResponse:
        events = await session_store.list_events(
            session_id=session_id,
            min_offset=min_offset,
            exclude_deleted=True,
        )

        deleted_event_ids = [await session_store.delete_event(e.id) for e in events]

        return DeleteEventsResponse(event_ids=[id for id in deleted_event_ids if id is not None])

    return router