opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: export local and view exported & project sessions in web UI

Open ndraiman opened this issue 6 months ago • 2 comments

Draft PR: Session Export and Local Viewing

Looking For Feedback

[!Note] This is a draft PR looking for feedback on the implementation approach and user experience.

Current Draft Limitation:

  • Need to run opencode serve.
  • Need to run web ui dev server bun --cwd packages/web dev.
  • Web UI port is hardcoded

https://github.com/user-attachments/assets/24a0cdfd-1093-4c07-80b4-98539f207f81

Summary

This PR adds the ability to export chat sessions to local storage and view them through a local web interface. Users can now:

  • Export active sessions to local JSON files stored in the config directory
  • Access exported sessions via local URLs (e.g., http://localhost:4321/local/{sessionId})
  • Browse and manage exported sessions through new API endpoints

Key Changes

Server

  • New API endpoints (packages/opencode/src/server/server.ts):

    • POST /session/:id/export - Export a session to local storage
    • GET /session/export - List all exported sessions
    • GET /session/:id/export - Retrieve specific exported session data
  • Session export functionality (packages/opencode/src/session/index.ts):

    • Export sessions as JSON files to ~/.config/opencode/session-exports/
    • Include session metadata, messages, and export timestamp
    • Generate local URLs for web access

TUI

  • New export command (packages/tui/internal/commands/command.go):
    • Added SessionExportCommand with trigger "export"
  • Export functionality (packages/tui/internal/tui/tui.go):
    • Export current session and copy local URL to clipboard
    • Success/error toast notifications
  • Generated client updates - Updated OpenAPI spec and Go client code

User Experience

  1. User runs export command in active session
  2. Session gets exported to local JSON file
  3. Local URL (http://localhost:4321/local/{sessionId}) copied to clipboard
  4. User can access exported session via browser at that URL

Technical Details

  • Export files stored in ~/.config/opencode/session-exports/{sessionId}.json
  • Local web server runs on port 4321
  • Exported sessions include full conversation history and metadata
  • Error handling for missing sessions and file operations

ndraiman avatar Jun 27 '25 15:06 ndraiman

Fixed conflicts with the new SDKs. But now I need the Client SDK to be regenerated to support the Export commands

ndraiman avatar Jun 28 '25 03:06 ndraiman

Added a small POC in a separate branch with added Streaming support for messages API and allowing to invoke the agent from the Web UI:

https://github.com/user-attachments/assets/c29d7592-1a20-4d6f-9251-6589c79c7d70

To view the diff with this PR click here

It's still rough and first draft, didn't want to modify the Share.tsx component for now to avoid conflicts with your changes.

Would love your opinion on this whole direction @thdxr @adamdotdevin 🙏🏻

ndraiman avatar Jun 28 '25 13:06 ndraiman

not relevant anymore.

ndraiman avatar Dec 25 '25 12:12 ndraiman