const tokenResponse = await fetch(
"https://app.runtm.com/api/cloud/sessions/ses_abc123/ws-token",
{
method: "POST",
headers: {
"Authorization": "Bearer runtm_sk_live_abc123...",
"Content-Type": "application/json",
},
body: JSON.stringify({ capability: "terminal" }),
}
);
const { token } = await tokenResponse.json();
const ws = new WebSocket(
`wss://app.runtm.com/api/cloud/sessions/ses_abc123/terminal?token=${token}`
);
ws.onopen = () => {
ws.send(JSON.stringify({ type: "resize", cols: 80, rows: 24 }));
ws.send("echo 'Hello from the API'\r");
};
ws.onmessage = (event) => {
process.stdout.write(event.data);
};
ws.onclose = (event) => {
console.log(`Disconnected: ${event.code} ${event.reason}`);
};