mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
refactor(database): update default source values to 'surfsense' for chat threads and messages
This commit is contained in:
parent
c958fe5bc6
commit
3faaa25af6
4 changed files with 11 additions and 8 deletions
|
|
@ -424,7 +424,7 @@ def upgrade() -> None:
|
||||||
if not _column_exists(conn, "new_chat_threads", "source"):
|
if not _column_exists(conn, "new_chat_threads", "source"):
|
||||||
op.add_column(
|
op.add_column(
|
||||||
"new_chat_threads",
|
"new_chat_threads",
|
||||||
sa.Column("source", sa.Text(), nullable=False, server_default="web"),
|
sa.Column("source", sa.Text(), nullable=False, server_default="surfsense"),
|
||||||
)
|
)
|
||||||
op.alter_column("new_chat_threads", "source", type_=sa.Text())
|
op.alter_column("new_chat_threads", "source", type_=sa.Text())
|
||||||
if not _column_exists(conn, "new_chat_threads", "external_chat_binding_id"):
|
if not _column_exists(conn, "new_chat_threads", "external_chat_binding_id"):
|
||||||
|
|
@ -454,7 +454,7 @@ def upgrade() -> None:
|
||||||
if not _column_exists(conn, "new_chat_messages", "source"):
|
if not _column_exists(conn, "new_chat_messages", "source"):
|
||||||
op.add_column(
|
op.add_column(
|
||||||
"new_chat_messages",
|
"new_chat_messages",
|
||||||
sa.Column("source", sa.Text(), nullable=False, server_default="web"),
|
sa.Column("source", sa.Text(), nullable=False, server_default="surfsense"),
|
||||||
)
|
)
|
||||||
op.alter_column("new_chat_messages", "source", type_=sa.Text())
|
op.alter_column("new_chat_messages", "source", type_=sa.Text())
|
||||||
if not _column_exists(conn, "new_chat_messages", "platform_metadata"):
|
if not _column_exists(conn, "new_chat_messages", "platform_metadata"):
|
||||||
|
|
|
||||||
|
|
@ -696,9 +696,9 @@ class NewChatThread(BaseModel, TimestampMixin):
|
||||||
# agent_llm_id changes). Unindexed: all reads are by primary key.
|
# agent_llm_id changes). Unindexed: all reads are by primary key.
|
||||||
pinned_llm_config_id = Column(Integer, nullable=True)
|
pinned_llm_config_id = Column(Integer, nullable=True)
|
||||||
|
|
||||||
# Surface metadata for web and external chat threads. Zero publishes all
|
# Surface metadata for first-party SurfSense and external chat threads.
|
||||||
# chat-message sources; the UI can decide which surfaces to render.
|
# Zero publishes all chat-message sources; the UI can decide which surfaces to render.
|
||||||
source = Column(Text, nullable=False, default="web", server_default="web")
|
source = Column(Text, nullable=False, default="surfsense", server_default="surfsense")
|
||||||
external_chat_binding_id = Column(
|
external_chat_binding_id = Column(
|
||||||
BigInteger,
|
BigInteger,
|
||||||
ForeignKey("external_chat_bindings.id", ondelete="SET NULL"),
|
ForeignKey("external_chat_bindings.id", ondelete="SET NULL"),
|
||||||
|
|
@ -786,7 +786,7 @@ class NewChatMessage(BaseModel, TimestampMixin):
|
||||||
|
|
||||||
# Mirrors the parent thread source for publication-level filtering.
|
# Mirrors the parent thread source for publication-level filtering.
|
||||||
# This denormalization avoids join-dependent logical replication rules.
|
# This denormalization avoids join-dependent logical replication rules.
|
||||||
source = Column(Text, nullable=False, default="web", server_default="web")
|
source = Column(Text, nullable=False, default="surfsense", server_default="surfsense")
|
||||||
platform_metadata = Column(JSONB, nullable=True)
|
platform_metadata = Column(JSONB, nullable=True)
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,10 @@ async def call_agent_for_gateway(
|
||||||
await stream.aclose()
|
await stream.aclose()
|
||||||
await session.execute(
|
await session.execute(
|
||||||
update(NewChatMessage)
|
update(NewChatMessage)
|
||||||
.where(NewChatMessage.thread_id == thread.id, NewChatMessage.source == "web")
|
.where(
|
||||||
|
NewChatMessage.thread_id == thread.id,
|
||||||
|
NewChatMessage.source == "surfsense",
|
||||||
|
)
|
||||||
.values(source="telegram")
|
.values(source="telegram")
|
||||||
)
|
)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ The backend is the core of SurfSense. Follow these steps to set it up:
|
||||||
|
|
||||||
### Optional: Telegram External Chat Surface
|
### Optional: Telegram External Chat Surface
|
||||||
|
|
||||||
SurfSense can expose the same canonical chat agent through Telegram. The `external_chat_*` tables store adapter identity, delivery configuration, and durable inbox rows. The actual chat thread and messages remain in `new_chat_threads` and `new_chat_messages`, and all chat-message sources are eligible for Zero replication so a future SurfSense UI layer can render external chat surfaces. The web app initially shows pairing, health, revoke, and resume controls under **User Settings > Messaging Channels**.
|
SurfSense can expose the same canonical chat agent through Telegram. The `external_chat_*` tables store adapter identity, delivery configuration, and durable inbox rows. The actual chat thread and messages remain in `new_chat_threads` and `new_chat_messages`, with first-party web/desktop chats marked as `source="surfsense"` and external surfaces marked by platform, such as `source="telegram"`. All chat-message sources are eligible for Zero replication so a future SurfSense UI layer can render external chat surfaces. The web app initially shows pairing, health, revoke, and resume controls under **User Settings > Messaging Channels**.
|
||||||
|
|
||||||
Add these variables to `surfsense_backend/.env` when enabling the Telegram surface:
|
Add these variables to `surfsense_backend/.env` when enabling the Telegram surface:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue