Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
425e498
first part
matusdrobuliak66 Aug 13, 2025
b202cf8
daily work
matusdrobuliak66 Aug 13, 2025
3faff0f
Handles support conversations without project ID
matusdrobuliak66 Aug 14, 2025
f119400
Splits message endpoints to dedicated controller
matusdrobuliak66 Aug 14, 2025
8a4675f
Refactors conversation endpoints for unified error handling
matusdrobuliak66 Aug 14, 2025
e513c15
Merge branch 'master' into first-iteration-backend-for-support-center
matusdrobuliak66 Aug 14, 2025
7eb1972
Adds support for extra context in conversations
matusdrobuliak66 Aug 14, 2025
23e81f7
Adds REST API endpoints for conversations and messages
matusdrobuliak66 Aug 14, 2025
460a21a
fix
matusdrobuliak66 Aug 14, 2025
5c1533a
Refactors conversation type argument naming for clarity
matusdrobuliak66 Aug 14, 2025
9d582b2
Clarifies API entrypoint section headers
matusdrobuliak66 Aug 14, 2025
877e4df
Renames parameter to avoid shadowing built-in type
matusdrobuliak66 Aug 15, 2025
470fbab
Fixes SQL filtering for conversation type matching
matusdrobuliak66 Aug 15, 2025
694770b
Improves error message for invalid conversation type
matusdrobuliak66 Aug 15, 2025
54c77fc
Adds support for SUPPORT conversation type and REST API tests
matusdrobuliak66 Aug 15, 2025
ea9ca85
add final tests
matusdrobuliak66 Aug 15, 2025
c1d8438
Merge branch 'master' into first-iteration-backend-for-support-center
matusdrobuliak66 Aug 15, 2025
9a36762
fix migration alembic version
matusdrobuliak66 Aug 15, 2025
d0cfbd2
Merge branch 'master' into first-iteration-backend-for-support-center
matusdrobuliak66 Aug 15, 2025
b6daa89
Merge branch 'master' into first-iteration-backend-for-support-center
matusdrobuliak66 Aug 16, 2025
083b377
Merge branch 'master' into first-iteration-backend-for-support-center
matusdrobuliak66 Aug 18, 2025
f65ce8b
Refactors conversation endpoints to use query helpers
matusdrobuliak66 Aug 18, 2025
8a31d1a
fix
matusdrobuliak66 Aug 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions api/specs/web-server/_conversations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
"""Helper script to automatically generate OAS

This OAS are the source of truth
"""

# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=unused-variable
# pylint: disable=too-many-arguments


from typing import Annotated

from _common import as_query
from fastapi import APIRouter, Depends, status
from models_library.api_schemas_webserver.conversations import (
ConversationMessagePatch,
ConversationMessageRestGet,
ConversationPatch,
ConversationRestGet,
)
from models_library.generics import Envelope
from models_library.rest_pagination import Page
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.conversations._controller._common import (
ConversationPathParams,
)
from simcore_service_webserver.conversations._controller._conversations_messages_rest import (
_ConversationMessageCreateBodyParams,
_ConversationMessagePathParams,
_ListConversationMessageQueryParams,
)
from simcore_service_webserver.conversations._controller._conversations_rest import (
_ConversationsCreateBodyParams,
_GetConversationsQueryParams,
_ListConversationsQueryParams,
)

router = APIRouter(
prefix=f"/{API_VTAG}",
tags=[
"conversations",
],
)


#
# API entrypoints CONVERSATIONS
#


@router.post(
"/conversations",
response_model=Envelope[ConversationRestGet],
status_code=status.HTTP_201_CREATED,
)
async def create_conversation(
_body: _ConversationsCreateBodyParams,
_query: Annotated[_GetConversationsQueryParams, Depends()],
): ...


@router.get(
"/conversations",
response_model=Page[ConversationRestGet],
)
async def list_conversations(
_query: Annotated[_ListConversationsQueryParams, Depends()],
): ...


@router.put(
"/conversations/{conversation_id}",
response_model=Envelope[ConversationRestGet],
)
async def update_conversation(
_params: Annotated[ConversationPathParams, Depends()],
_body: ConversationPatch,
_query: Annotated[as_query(_GetConversationsQueryParams), Depends()],
): ...


@router.delete(
"/conversations/{conversation_id}",
status_code=status.HTTP_204_NO_CONTENT,
)
async def delete_conversation(
_params: Annotated[ConversationPathParams, Depends()],
_query: Annotated[as_query(_GetConversationsQueryParams), Depends()],
): ...


@router.get(
"/conversations/{conversation_id}",
response_model=Envelope[ConversationRestGet],
)
async def get_conversation(
_params: Annotated[ConversationPathParams, Depends()],
_query: Annotated[as_query(_GetConversationsQueryParams), Depends()],
): ...


#
# API entrypoints CONVERSATION MESSAGES
#


@router.post(
"/conversations/{conversation_id}/messages",
response_model=Envelope[ConversationMessageRestGet],
status_code=status.HTTP_201_CREATED,
)
async def create_conversation_message(
_params: Annotated[ConversationPathParams, Depends()],
_body: _ConversationMessageCreateBodyParams,
): ...


@router.get(
"/conversations/{conversation_id}/messages",
response_model=Page[ConversationMessageRestGet],
)
async def list_conversation_messages(
_params: Annotated[ConversationPathParams, Depends()],
_query: Annotated[as_query(_ListConversationMessageQueryParams), Depends()],
): ...


@router.put(
"/conversations/{conversation_id}/messages/{message_id}",
response_model=Envelope[ConversationMessageRestGet],
)
async def update_conversation_message(
_params: Annotated[_ConversationMessagePathParams, Depends()],
_body: ConversationMessagePatch,
): ...


@router.delete(
"/conversations/{conversation_id}/messages/{message_id}",
status_code=status.HTTP_204_NO_CONTENT,
)
async def delete_conversation_message(
_params: Annotated[_ConversationMessagePathParams, Depends()],
): ...


@router.get(
"/conversations/{conversation_id}/messages/{message_id}",
response_model=Envelope[ConversationMessageRestGet],
)
async def get_conversation_message(
_params: Annotated[_ConversationMessagePathParams, Depends()],
): ...
2 changes: 1 addition & 1 deletion api/specs/web-server/_projects_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import Annotated

from fastapi import APIRouter, Depends, status
from models_library.api_schemas_webserver.projects_conversations import (
from models_library.api_schemas_webserver.conversations import (
ConversationMessageRestGet,
ConversationRestGet,
)
Expand Down
1 change: 1 addition & 0 deletions api/specs/web-server/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# core ---
"_auth",
"_auth_api_keys",
"_conversations",
"_groups",
"_tags",
"_tags_groups", # after _tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..projects import ProjectID
from ._base import InputSchema, OutputSchema

### PROJECT CONVERSATION -------------------------------------------------------------------
### CONVERSATION -------------------------------------------------------------------


class ConversationRestGet(OutputSchema):
Expand All @@ -28,6 +28,7 @@ class ConversationRestGet(OutputSchema):
type: ConversationType
created: datetime
modified: datetime
extra_context: dict[str, str]

@classmethod
def from_domain_model(cls, domain: ConversationGetDB) -> Self:
Expand All @@ -40,14 +41,15 @@ def from_domain_model(cls, domain: ConversationGetDB) -> Self:
type=domain.type,
created=domain.created,
modified=domain.modified,
extra_context=domain.extra_context,
)


class ConversationPatch(InputSchema):
name: str | None = None


### PROJECT CONVERSATION MESSAGES ---------------------------------------------------------------
### CONVERSATION MESSAGES ---------------------------------------------------------------


class ConversationMessageRestGet(OutputSchema):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from enum import auto
from typing import Annotated, TypeAlias
from typing import Annotated, Any, TypeAlias
from uuid import UUID

from models_library.groups import GroupID
Expand All @@ -23,6 +23,7 @@ class ConversationType(StrAutoEnum):
PROJECT_ANNOTATION = (
auto() # Something like sticky note, can be located anywhere in the pipeline UI
)
SUPPORT = auto() # Support conversation


class ConversationMessageType(StrAutoEnum):
Expand All @@ -44,6 +45,7 @@ class ConversationGetDB(BaseModel):
project_uuid: ProjectID | None
user_group_id: GroupID
type: ConversationType
extra_context: dict[str, Any]

# states
created: datetime
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""modify conversations

Revision ID: b566f1b29012
Revises: 5b998370916a
Create Date: 2025-08-14 15:02:54.784186+00:00

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "b566f1b29012"
down_revision = "5b998370916a"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"conversations",
sa.Column(
"extra_context",
postgresql.JSONB(astext_type=sa.Text()),
server_default=sa.text("'{}'::jsonb"),
nullable=False,
),
)
op.add_column(
"products",
sa.Column("support_standard_group_id", sa.BigInteger(), nullable=True),
)
op.create_foreign_key(
"fk_products_support_standard_group_id",
"products",
"groups",
["support_standard_group_id"],
["gid"],
onupdate="CASCADE",
ondelete="SET NULL",
)

op.execute(
"""
ALTER TYPE conversationtype ADD VALUE 'SUPPORT';
"""
)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"fk_products_support_standard_group_id", "products", type_="foreignkey"
)
op.drop_column("products", "support_standard_group_id")
op.drop_column("conversations", "extra_context")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.dialects.postgresql import JSONB, UUID

from ._common import RefActions, column_created_datetime, column_modified_datetime
from .base import metadata
Expand All @@ -12,6 +12,7 @@
class ConversationType(enum.Enum):
PROJECT_STATIC = "PROJECT_STATIC" # Static conversation for the project
PROJECT_ANNOTATION = "PROJECT_ANNOTATION" # Something like sticky note, can be located anywhere in the pipeline UI
SUPPORT = "SUPPORT" # Support conversation


conversations = sa.Table(
Expand Down Expand Up @@ -70,6 +71,13 @@ class ConversationType(enum.Enum):
nullable=False,
doc="Product name identifier. If None, then the item is not exposed",
),
sa.Column(
"extra_context",
JSONB,
nullable=False,
server_default=sa.text("'{}'::jsonb"),
doc="Free JSON to store extra context",
),
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
)
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,18 @@ class ProductLoginSettingsDict(TypedDict, total=False):
nullable=True,
doc="Group associated to this product",
),
sa.Column(
"support_standard_group_id",
sa.BigInteger,
sa.ForeignKey(
groups.c.gid,
name="fk_products_support_standard_group_id",
ondelete=RefActions.SET_NULL,
onupdate=RefActions.CASCADE,
),
unique=False,
nullable=True,
doc="Group associated to this product support",
),
sa.PrimaryKeyConstraint("name", name="products_pk"),
)
Loading
Loading