feat: Add WebMCP token polling for automatic browser connection
- Add token API endpoint to server for storing/retrieving pending tokens - Add token polling in frontend to auto-detect and connect with tokens - Add xterm dependencies for terminal functionality - Add terminal page support in toolRegistry
This commit is contained in:
@@ -4,6 +4,9 @@ import { spawn, type IPty } from '@skitee3000/bun-pty'
|
||||
const PORT_HTTP = 4101
|
||||
const PORT_TERMINAL = 4103
|
||||
|
||||
// WebMCP token storage (in-memory, for passing token to browser)
|
||||
let pendingWebMCPToken: { token: string; createdAt: Date } | null = null
|
||||
|
||||
// Terminal types
|
||||
interface TerminalSession {
|
||||
id: string
|
||||
@@ -299,6 +302,43 @@ Bun.serve({
|
||||
return Response.json({ status: 'ok', timestamp: new Date().toISOString() }, { headers: corsHeaders })
|
||||
}
|
||||
|
||||
// WebMCP Token API - para pasar token al browser
|
||||
if (url.pathname === '/api/webmcp-token') {
|
||||
if (req.method === 'GET') {
|
||||
if (pendingWebMCPToken) {
|
||||
// Check if token is not expired (5 minutes)
|
||||
const age = Date.now() - pendingWebMCPToken.createdAt.getTime()
|
||||
if (age < 5 * 60 * 1000) {
|
||||
return Response.json({
|
||||
token: pendingWebMCPToken.token,
|
||||
createdAt: pendingWebMCPToken.createdAt.toISOString()
|
||||
}, { headers: corsHeaders })
|
||||
}
|
||||
// Token expired
|
||||
pendingWebMCPToken = null
|
||||
}
|
||||
return Response.json({ token: null }, { headers: corsHeaders })
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const body = await req.json()
|
||||
if (body.token) {
|
||||
pendingWebMCPToken = {
|
||||
token: body.token,
|
||||
createdAt: new Date()
|
||||
}
|
||||
console.log('[WebMCP] Token received and stored')
|
||||
return Response.json({ success: true }, { headers: corsHeaders })
|
||||
}
|
||||
return Response.json({ error: 'Token required' }, { status: 400, headers: corsHeaders })
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
pendingWebMCPToken = null
|
||||
return Response.json({ success: true }, { headers: corsHeaders })
|
||||
}
|
||||
}
|
||||
|
||||
// API de Componentes Vue
|
||||
if (url.pathname === '/api/components') {
|
||||
if (req.method === 'GET') {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
{
|
||||
"name": "agent-ui-server",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "bun run index.ts",
|
||||
"dev": "bun --watch run index.ts"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@skitee3000/bun-pty": "^0.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user