Director icon indicating copy to clipboard operation
Director copied to clipboard

feat: rename and share session handling

Open omgate234 opened this issue 1 year ago • 1 comments

Features added

  • Added name column to sessions table for renaming sessions
  • Added is_public column to sessions table for allowing session sharing
    • This allows user to have sharable links of their chats if they were to independently host them
  • Added DB handlers and routes for making renaming and sharing possible
  • UI synced with the videodb-chat PR: https://github.com/video-db/videodb-chat/pull/102

Summary by CodeRabbit

  • New Features

    • Public, read-only share view at /share/:sessionId with a minimal full-viewport chat.
    • Automatic session naming via LLM when creating unnamed sessions.
  • API

    • POST to create sessions; endpoints to rename sessions, toggle public visibility, and fetch public sessions with conversations.
    • Socket support to join session rooms for targeted real-time updates.
  • Frontend

    • New public hook to load/display shared sessions and assets.
  • Chores

    • DB schema/storage extended for session names and public visibility.
  • Bug Fixes

    • Real-time emissions scoped to session rooms with improved handling and logging.

omgate234 avatar Sep 23 '25 10:09 omgate234

Walkthrough

Adds public session sharing: core Session gains update() and session-scoped output broadcasting; DB interfaces and Postgres/SQLite implementations add session name/is_public schema, update/delete/make_public/get_public methods; API routes and socket handlers add public endpoints and room join semantics; frontend adds Share route, ShareView, and publicUseVideoDBAgent hook.

Changes

Cohort / File(s) Summary
Session core API & publish flow
backend/director/core/session.py
Adds Session.update(**kwargs) delegating to db.update_session(...); changes OutputMessage publish to emit to room=self.session_id, adds room-scoped logs, and moves DB write after emit attempt.
DB abstraction contract
backend/director/db/base.py
Adds abstract methods: update_session(session_id, **kwargs), delete_session(session_id) -> tuple[bool, list], make_session_public(session_id, is_public), get_public_session(session_id) -> dict.
Postgres implementation & init
backend/director/db/postgres/db.py, .../initialize.py
PostgresDB.__init__ now calls initialize_postgres(); create_session accepts name; implements update_session, make_session_public, get_public_session; delete_session returns (bool, list); schema init adds name and is_public columns and ALTERs if missing.
SQLite implementation & init
backend/director/db/sqlite/db.py, .../initialize.py
SQLiteDB.__init__ calls initialize_sqlite(); create_session accepts name; implements update_session, make_session_public, get_public_session; delete_session returns (bool, list) with failure details; schema includes name and is_public and runtime migration adds missing columns.
API routes (HTTP)
backend/director/entrypoint/api/routes.py
Adds/extends session routes: POST /<session_id> (create), PUT /<session_id>/rename (rename), PUT /<session_id>/public (toggle public), and GET /public/<session_id> (fetch public session). Includes validation and DB checks.
Handler
backend/director/handler.py
Adds SessionHandler.rename_session(session_id, new_name) and create_session(message) (creates session and optionally auto-generates a name via LLM, then renames).
Socket IO namespace
backend/director/entrypoint/api/socket_io.py
Adds on_connect, on_join_session, on_disconnect; on_chat now requires session_id, auto-joins join_room(session_id), and emits errors if session_id missing.
Constants / LLM prompt
backend/director/constants.py
Adds CHAT_NAMING_SYSTEM_PROMPT constant used for LLM-derived session naming.
Frontend public hook
frontend/src/hooks/shareViewHandler.js
Adds publicUseVideoDBAgent(config, sessionId) hook exposing public session/conversation state and many action stubs (fetch, upload, makeSessionPublic, etc.) and performs initial public-session fetch.
Router
frontend/src/router/index.js
Imports ShareView and adds route { path: "/share/:sessionId", name: "Share", component: ShareView }.
Share view
frontend/src/views/ShareView.vue
New ShareView component that mounts publicUseVideoDBAgent, configures endpoints, and renders a minimal full-viewport public chat UI.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as Browser (Share URL)
  participant Router as Frontend Router
  participant ShareView as ShareView.vue
  participant Hook as publicUseVideoDBAgent
  participant API as /api
  participant DB as DB (Postgres/SQLite)

  User->>Router: Navigate /share/:sessionId
  Router->>ShareView: Mount component
  ShareView->>Hook: init(sessionId)
  Hook->>API: GET /sessions/public/:sessionId
  API->>DB: get_public_session(sessionId)
  DB-->>API: session (if is_public=true)
  API->>DB: get_conversations(sessionId)
  DB-->>API: conversations[]
  API-->>Hook: { session, conversations }
  Hook-->>ShareView: reactive data
  ShareView-->>User: Render public chat
  note right of API: Only sessions with is_public=true are returned
sequenceDiagram
  autonumber
  actor Owner as Authenticated Client
  participant API as /api
  participant Handler as SessionHandler
  participant Core as Session (core)
  participant DB as DB

  Owner->>API: PUT /sessions/:id/rename { name }
  API->>Handler: rename_session(id, name)
  Handler->>Core: Session(id).update(name=name)
  Core->>DB: update_session(id, name=name, updated_at=now)
  DB-->>Core: bool
  Core-->>Handler: result
  Handler-->>API: payload
  API-->>Owner: 200/500
sequenceDiagram
  autonumber
  actor Client as Websocket Client
  participant Socket as ChatNamespace
  participant Room as Socket Room (session_id)
  participant Core as Session (publisher)

  Client->>Socket: connect
  Socket->>Client: connected ack
  Client->>Socket: join_session { session_id }
  Socket->>Room: join room session_id
  Socket->>Client: event session_joined
  Core->>Socket: publish OutputMessage (room=session_id)
  Socket->>Room: emit output_message (room=session_id)
  Room-->>Client: receives output_message

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • video-db/Director#152 — touches LLM integration and CHAT_NAMING_SYSTEM_PROMPT usage; likely related to LLM naming changes and get_default_llm adjustments.

Suggested reviewers

  • ankit-v2-3

Poem

I thump my paws—share links appear,
Names and rooms now crisp and clear,
Public burrows open wide,
Chats hop out and peers can glide,
Schema carrots, sockets bright—🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “feat: rename and share session handling” succinctly and accurately summarizes the primary additions of session renaming and sharing capabilities introduced in this changeset, matching the database, API, and UI updates described.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Sep 23 '25 10:09 coderabbitai[bot]