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: "prompt" }),
}
);
const { token } = await tokenResponse.json();
const ws = new WebSocket(
`wss://app.runtm.com/api/cloud/sessions/ses_abc123/tabs/tab_0/prompt?token=${token}`
);
ws.onopen = () => {
ws.send(JSON.stringify({
type: "prompt_start",
content: "Add input validation to the login form",
}));
};
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
switch (msg.type) {
case "token":
process.stdout.write(msg.content);
break;
case "tool_use":
console.log(`\n[Tool: ${msg.tool}]`);
break;
case "tool_result":
console.log(`[Result: ${msg.output}]`);
break;
case "prompt_end":
console.log(`\n[Done - ${msg.usage.output_tokens} tokens]`);
break;
case "error":
console.error(`\n[Error: ${msg.message}]`);
break;
}
};