Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 0.1.11

- Change: every open now travels through the plugin's own server RPC. `/media`
and autoplay call `context.client.rpc(Media).open(...)`, the server part emits
`open`, and the TUI subscriber renders. One path for the slash command,
autoplay and any external caller, all inside the running client. If the
server part is not loaded the call rejects and the local opener runs, so a
TUI-only install keeps working.
- Fix: the README's RPC example sent the arguments at the top level. The HTTP
endpoint expects `{"input": …}`, and it authenticates with HTTP Basic
(`opencode` plus the service password). Both are now documented.

## 0.1.10

Open the panel from outside the TUI, for the session you are viewing.
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ package ships a server part that exposes an RPC, and the TUI part subscribes to
its events:

```bash
opencode api POST /api/rpc/media/open -d '{"source":"/home/user/clips/demo.mp4"}'
opencode api POST /api/rpc/media/close
opencode api POST /api/rpc/media/open -d '{"input":{"source":"/home/user/clips/demo.mp4"}}'
opencode api POST /api/rpc/media/close -d '{"input":{}}'

The body is an envelope: the method's own arguments go under `input`. A body of
`{"source": …}` is rejected with `rpc.invalid_input: Expected object`. The
service authenticates with HTTP Basic: username `opencode` and the password in
`service.json`, over the channel's port (`49374` for `latest`, `0xc0de`).

Every open, including `/media` and autoplay, travels through this RPC: the TUI
part calls it, the server part emits, and the TUI renders the event. The plugin
never shells out.
```

Any client with the server address works the same way, including
Expand Down
18 changes: 16 additions & 2 deletions src/tui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default Plugin.define({
}, 1000 / next.fps);
}

function open(source: string): boolean {
function show(source: string): boolean {
let extracted: ReturnType<typeof extractFrames>;
try {
extracted = extractFrames(source, options);
Expand Down Expand Up @@ -231,11 +231,25 @@ export default Plugin.define({
// a client (script, agent, another plugin) can call. The panel itself is
// unreachable from outside the TUI process, so the call arrives as an event
// and this subscriber is what opens it.
// Every open goes through the server: `open` below calls the RPC, the
// server emits, and this subscriber renders. One path for the slash
// command, autoplay and any external caller, and no shell or CLI in it.
// If the server part is not loaded the call rejects and the local opener
// runs instead, so a TUI-only install keeps working.
const remote = context.client.rpc(Media);
const stopOpen = remote.events.on("open", (event) => {
const data = event.data as { source?: unknown };
if (typeof data.source === "string") open(data.source);
if (typeof data.source === "string") show(data.source);
});

function open(source: string): void {
const call = remote.open;
if (typeof call !== "function") {
show(source);
return;
}
Promise.resolve(call({ source })).catch(() => show(source));
}
const stopClose = remote.events.on("close", () => {
context.ui.panel.close();
});
Expand Down