Skip to content

Conversation

@code-yeongyu
Copy link
Contributor

@code-yeongyu code-yeongyu commented Jan 1, 2026

Summary

Add plugin API endpoint (POST /session/{sessionID}/select) that allows plugins to programmatically navigate the TUI to a different session.

Changes

Server (packages/opencode/src/server/server.ts)

  • Add POST /session/:sessionID/select endpoint
  • Validates session exists before emitting event
  • Returns 404 for invalid session ID

TUI (packages/opencode/src/cli/cmd/tui/)

  • Add SessionSelect event type in event.ts
  • Handle SessionSelect event in app.tsx to switch displayed session

SDK (packages/sdk/js/)

  • Regenerated with client.session.select() method

Usage

From Plugin (Native)

import type { Plugin } from "@opencode-ai/plugin"

const plugin: Plugin = async ({ client }) => ({
  tool: {
    switch_session: {
      description: "Switch to a different session",
      parameters: z.object({ sessionID: z.string() }),
      async execute({ parameters }) {
        await client.session.select({ sessionID: parameters.sessionID })
        return { output: `Switched to session ${parameters.sessionID}` }
      },
    },
  },
})

export default plugin

From External SDK

import { createClient } from "@opencode-ai/sdk"

const client = createClient({ baseUrl: "http://localhost:34127" })
await client.session.select({ sessionID: "ses_abc123" })

Add plugin API endpoint (POST /session/{sessionID}/select) that allows plugins to change the currently viewed session in the TUI. Implements SessionSelect event type and corresponding event handler in TUI app for seamless navigation.

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
Add unit tests for POST /session/:sessionID/select endpoint:
- 200 response for valid session ID
- 404 response for non-existent session
- 400 response for invalid session ID format

GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant