Browse Source

feat(tui): unshare command

adamdottv 7 months ago
parent
commit
8825cd3811

+ 4 - 1
packages/opencode/src/share/share.ts

@@ -67,9 +67,12 @@ export namespace Share {
   }
 
   export async function remove(id: string) {
+    const share = await Session.getShare(id).catch(() => {})
+    if (!share) return
+    const { secret } = share
     return fetch(`${URL}/share_delete`, {
       method: "POST",
-      body: JSON.stringify({ id }),
+      body: JSON.stringify({ id, secret }),
     }).then((x) => x.json())
   }
 }

+ 8 - 1
packages/tui/internal/commands/command.go

@@ -75,6 +75,7 @@ const (
 	SessionNewCommand           CommandName = "session_new"
 	SessionListCommand          CommandName = "session_list"
 	SessionShareCommand         CommandName = "session_share"
+	SessionUnshareCommand       CommandName = "session_unshare"
 	SessionInterruptCommand     CommandName = "session_interrupt"
 	SessionCompactCommand       CommandName = "session_compact"
 	ToolDetailsCommand          CommandName = "tool_details"
@@ -160,6 +161,12 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
 			Keybindings: parseBindings("<leader>s"),
 			Trigger:     "share",
 		},
+		{
+			Name:        SessionUnshareCommand,
+			Description: "unshare session",
+			Keybindings: parseBindings("<leader>u"),
+			Trigger:     "unshare",
+		},
 		{
 			Name:        SessionInterruptCommand,
 			Description: "interrupt session",
@@ -289,7 +296,7 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
 		{
 			Name:        MessagesRevertCommand,
 			Description: "revert message",
-			Keybindings: parseBindings("<leader>u"),
+			Keybindings: parseBindings("<leader>r"),
 		},
 		{
 			Name:        AppExitCommand,

+ 5 - 2
packages/tui/internal/components/chat/messages.go

@@ -309,9 +309,12 @@ func (m *messagesComponent) header(width int) string {
 	base := styles.NewStyle().Foreground(t.Text()).Background(t.Background()).Render
 	muted := styles.NewStyle().Foreground(t.TextMuted()).Background(t.Background()).Render
 	headerLines := []string{}
-	headerLines = append(headerLines, util.ToMarkdown("# "+m.app.Session.Title, width-6, t.Background()))
+	headerLines = append(
+		headerLines,
+		util.ToMarkdown("# "+m.app.Session.Title, width-6, t.Background()),
+	)
 	if m.app.Session.Share.URL != "" {
-		headerLines = append(headerLines, muted(m.app.Session.Share.URL))
+		headerLines = append(headerLines, muted(m.app.Session.Share.URL+"  /unshare"))
 	} else {
 		headerLines = append(headerLines, base("/share")+muted(" to create a shareable link"))
 	}

+ 11 - 0
packages/tui/internal/tui/tui.go

@@ -827,6 +827,17 @@ func (a appModel) executeCommand(command commands.Command) (tea.Model, tea.Cmd)
 		shareUrl := response.Share.URL
 		cmds = append(cmds, tea.SetClipboard(shareUrl))
 		cmds = append(cmds, toast.NewSuccessToast("Share URL copied to clipboard!"))
+	case commands.SessionUnshareCommand:
+		if a.app.Session.ID == "" {
+			return a, nil
+		}
+		_, err := a.app.Client.Session.Unshare(context.Background(), a.app.Session.ID)
+		if err != nil {
+			slog.Error("Failed to unshare session", "error", err)
+			return a, toast.NewErrorToast("Failed to unshare session")
+		}
+		a.app.Session.Share.URL = ""
+		cmds = append(cmds, toast.NewSuccessToast("Session unshared successfully"))
 	case commands.SessionInterruptCommand:
 		if a.app.Session.ID == "" {
 			return a, nil