Skip to main content

Installation

npm install @radaros/transport express socket.io
Optional peer dependencies for specific features:
FeaturePackage
Swagger UIswagger-ui-express
File uploadsmulter

Express

createAgentRouter

import { createAgentRouter } from "@radaros/transport";

const router = createAgentRouter(opts: RouterOptions): Express.Router;
agents
Record<string, Agent>
Named agents to expose as endpoints.
teams
Record<string, Team>
Named teams to expose as endpoints.
workflows
Record<string, Workflow>
Named workflows to expose as endpoints.
middleware
RequestHandler[]
Express middleware applied to all routes.
swagger
SwaggerOptions
Swagger UI configuration.
fileUpload
boolean | FileUploadOptions
Enable multipart file upload handling.

Generated Endpoints

MethodPathDescription
POST/agents/:name/runRun agent, return JSON
POST/agents/:name/streamStream agent response via SSE
POST/teams/:name/runRun team, return JSON
POST/teams/:name/streamStream team response via SSE
POST/workflows/:name/runRun workflow, return JSON
GET/docsSwagger UI (if enabled)
GET/docs/spec.jsonOpenAPI spec JSON (if enabled)

Request Body

// JSON
{
  "input": "Hello",              // string or ContentPart[]
  "sessionId": "optional-id",
  "userId": "optional-user",
  "apiKey": "optional-key"
}

// Multipart (with fileUpload enabled)
// Form fields: input (text), files (file uploads)

Response

// Run endpoint
{
  "text": "Agent response",
  "toolCalls": [],
  "usage": { "promptTokens": 100, "completionTokens": 50, "totalTokens": 150 },
  "structured": null,
  "durationMs": 1234
}

// Stream endpoint (SSE)
data: {"type":"text","text":"Hello"}
data: {"type":"finish","finishReason":"stop"}

SwaggerOptions

interface SwaggerOptions {
  enabled?: boolean;
  title?: string;         // Default: "RadarOS API"
  description?: string;
  version?: string;       // Default: "1.0.0"
  routePrefix?: string;
  servers?: Array<{ url: string; description?: string }>;
  docsPath?: string;      // Default: "/docs"
  specPath?: string;      // Default: "/docs/spec.json"
}

generateOpenAPISpec

import { generateOpenAPISpec } from "@radaros/transport";

const spec = generateOpenAPISpec(routerOpts: RouterOptions, swaggerOpts?: SwaggerOptions);
Returns a complete OpenAPI 3.0.3 specification object with auto-generated paths, schemas, and security schemes based on the registered agents/teams/workflows.

FileUploadOptions

interface FileUploadOptions {
  maxFileSize?: number;        // Default: 52428800 (50MB)
  maxFiles?: number;           // Default: 10
  allowedMimeTypes?: string[];
}

createFileUploadMiddleware

import { createFileUploadMiddleware } from "@radaros/transport";

const upload = createFileUploadMiddleware(opts?: FileUploadOptions);

buildMultiModalInput

import { buildMultiModalInput } from "@radaros/transport";

const input = buildMultiModalInput(req.body, req.files);
// Returns string (text only) or ContentPart[] (text + files)

Middleware

errorHandler

import { errorHandler } from "@radaros/transport";

app.use("/api", router);
app.use(errorHandler);

requestLogger

import { requestLogger } from "@radaros/transport";

app.use(requestLogger);

Socket.IO

createAgentGateway

import { createAgentGateway } from "@radaros/transport";

createAgentGateway(opts: GatewayOptions): void;
agents
Record<string, Agent>
Named agents available via WebSocket.
teams
Record<string, Team>
Named teams available via WebSocket.
io
SocketIOServer
required
Socket.IO server instance.
namespace
string
default:"/radaros"
Socket.IO namespace.
authMiddleware
(socket, next) => void
Authentication middleware for connections.

Client Events (Send)

agent.run

socket.emit("agent.run", {
  name: "assistant",       // Agent name
  input: "Hello",          // User message
  sessionId?: "session-1", // Optional session ID
  apiKey?: "sk-..."        // Optional API key
});

team.run

socket.emit("team.run", {
  name: "research-team",
  input: "Analyze this topic",
  sessionId?: "session-1",
  apiKey?: "sk-..."
});

Server Events (Receive)

EventPayloadDescription
agent.chunk{ chunk: string }Text token
agent.tool.call{ toolName: string, args: null }Tool execution started
agent.tool.done{ toolCallId: string }Tool execution completed
agent.done{ output: { text: string } }Run completed
agent.error{ error: string }Error occurred

API Key Headers

The transport layer extracts API keys from these HTTP headers:
HeaderProvider
x-openai-api-keyOpenAI
x-google-api-keyGoogle
x-anthropic-api-keyAnthropic
x-api-keyGeneric fallback
Keys can also be passed in the request body as apiKey or via Socket.IO event payload.

A2A Server

Expose RadarOS agents as A2A-compliant HTTP endpoints.
import { createA2AServer } from "@radaros/transport";
import express from "express";

const app = express();

createA2AServer(app, {
  agents: { assistant, calculator },
  basePath: "/",
  provider: {
    organization: "MyCompany",
    url: "https://mycompany.com",
  },
  version: "1.0.0",
});
ConfigTypeDescription
agentsRecord<string, Agent>Map of agent name to Agent instance.
basePathstringBase path for the JSON-RPC endpoint (default "/").
provider{ organization, url? }Provider info for the Agent Card.
versionstringVersion string for the Agent Card (default "1.0.0").

Endpoints

EndpointDescription
GET /.well-known/agent.jsonAgent Card (discovery).
POST {basePath}JSON-RPC 2.0 endpoint.

JSON-RPC Methods

MethodDescription
message/sendSynchronous agent run. Returns completed task.
message/streamSSE streaming. Returns chunks as the agent generates.
tasks/getRetrieve a task by ID.
tasks/cancelCancel a running task.

Agent Card Generator

Generate Agent Cards from RadarOS agents without starting a server.
import { generateAgentCard, generateMultiAgentCard } from "@radaros/transport";

// Single agent card
const card = generateAgentCard(agent, "http://localhost:3001", {
  organization: "MyCompany",
});

// Multi-agent card
const multiCard = generateMultiAgentCard(
  { assistant, calculator },
  "http://localhost:3001",
  { organization: "MyCompany" },
);