@voltagent/server-core 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +23 -56
- package/dist/index.d.ts +23 -56
- package/dist/index.js +2 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -9
package/dist/index.d.mts
CHANGED
|
@@ -1345,6 +1345,26 @@ interface AuthProvider<TRequest = any> {
|
|
|
1345
1345
|
* These are added to the default public routes
|
|
1346
1346
|
*/
|
|
1347
1347
|
publicRoutes?: string[];
|
|
1348
|
+
/**
|
|
1349
|
+
* When true, all routes require authentication by default (opt-out model)
|
|
1350
|
+
* When false or undefined, only routes in PROTECTED_ROUTES require auth (opt-in model)
|
|
1351
|
+
*
|
|
1352
|
+
* Use this when you want to protect all routes by default and selectively
|
|
1353
|
+
* make certain routes public using the publicRoutes property.
|
|
1354
|
+
*
|
|
1355
|
+
* @default false
|
|
1356
|
+
* @example
|
|
1357
|
+
* ```typescript
|
|
1358
|
+
* // Protect all routes except those in publicRoutes
|
|
1359
|
+
* const authProvider: AuthProvider = {
|
|
1360
|
+
* type: 'clerk',
|
|
1361
|
+
* defaultPrivate: true,
|
|
1362
|
+
* publicRoutes: ['GET /health', 'POST /webhooks'],
|
|
1363
|
+
* verifyToken: async (token) => { ... }
|
|
1364
|
+
* }
|
|
1365
|
+
* ```
|
|
1366
|
+
*/
|
|
1367
|
+
defaultPrivate?: boolean;
|
|
1348
1368
|
}
|
|
1349
1369
|
|
|
1350
1370
|
/**
|
|
@@ -1372,63 +1392,10 @@ declare function pathMatches(path: string, pattern: string): boolean;
|
|
|
1372
1392
|
* @param method The HTTP method
|
|
1373
1393
|
* @param path The request path
|
|
1374
1394
|
* @param publicRoutes Additional public routes from config
|
|
1395
|
+
* @param defaultPrivate When true, routes require auth by default (opt-out model)
|
|
1375
1396
|
* @returns True if the route requires authentication
|
|
1376
1397
|
*/
|
|
1377
|
-
declare function requiresAuth(method: string, path: string, publicRoutes?: string[]): boolean;
|
|
1378
|
-
|
|
1379
|
-
/**
|
|
1380
|
-
* Framework-agnostic authentication middleware factory
|
|
1381
|
-
*/
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* Framework adapter for authentication middleware
|
|
1385
|
-
* Each framework implements this interface to bridge framework-specific APIs
|
|
1386
|
-
*/
|
|
1387
|
-
interface AuthFrameworkAdapter<TRequest, TResponse> {
|
|
1388
|
-
/**
|
|
1389
|
-
* Get the request path
|
|
1390
|
-
*/
|
|
1391
|
-
getPath(req: TRequest): string;
|
|
1392
|
-
/**
|
|
1393
|
-
* Get the request method
|
|
1394
|
-
*/
|
|
1395
|
-
getMethod(req: TRequest): string;
|
|
1396
|
-
/**
|
|
1397
|
-
* Get a request header
|
|
1398
|
-
*/
|
|
1399
|
-
getHeader(req: TRequest, name: string): string | undefined;
|
|
1400
|
-
/**
|
|
1401
|
-
* Get the raw request object (for providers that need it)
|
|
1402
|
-
*/
|
|
1403
|
-
getRawRequest(req: TRequest): Request;
|
|
1404
|
-
/**
|
|
1405
|
-
* Get the request body
|
|
1406
|
-
*/
|
|
1407
|
-
getBody(req: TRequest): Promise<any>;
|
|
1408
|
-
/**
|
|
1409
|
-
* Set authenticated user in the context
|
|
1410
|
-
*/
|
|
1411
|
-
setUser(context: any, user: any): void;
|
|
1412
|
-
/**
|
|
1413
|
-
* Modify request body to include user context
|
|
1414
|
-
*/
|
|
1415
|
-
injectUserIntoBody(req: TRequest, user: any): void;
|
|
1416
|
-
/**
|
|
1417
|
-
* Send an error response
|
|
1418
|
-
*/
|
|
1419
|
-
sendError(res: TResponse, message: string, status: number): any;
|
|
1420
|
-
/**
|
|
1421
|
-
* Send success to next middleware
|
|
1422
|
-
*/
|
|
1423
|
-
next(): any;
|
|
1424
|
-
}
|
|
1425
|
-
/**
|
|
1426
|
-
* Create authentication middleware with framework adapter
|
|
1427
|
-
* @param authProvider The authentication provider
|
|
1428
|
-
* @param adapter Framework-specific adapter
|
|
1429
|
-
* @returns Middleware function for the framework
|
|
1430
|
-
*/
|
|
1431
|
-
declare function createAuthMiddlewareFactory<TRequest, TResponse>(authProvider: AuthProvider<Request>, adapter: AuthFrameworkAdapter<TRequest, TResponse>): (req: TRequest, res: TResponse, next?: () => any) => Promise<any>;
|
|
1398
|
+
declare function requiresAuth(method: string, path: string, publicRoutes?: string[], defaultPrivate?: boolean): boolean;
|
|
1432
1399
|
|
|
1433
1400
|
/**
|
|
1434
1401
|
* JWT authentication options
|
|
@@ -1904,4 +1871,4 @@ declare abstract class BaseServerProvider implements IServerProvider {
|
|
|
1904
1871
|
private collectFeatureEndpoints;
|
|
1905
1872
|
}
|
|
1906
1873
|
|
|
1907
|
-
export { A2AServerLikeWithHandlers, type A2AServerLookupResult, AgentListSchema, AgentParamsSchema, AgentResponseSchema, ApiResponse, type
|
|
1874
|
+
export { A2AServerLikeWithHandlers, type A2AServerLookupResult, AgentListSchema, AgentParamsSchema, AgentResponseSchema, ApiResponse, type AuthProvider, type BaseCustomEndpointDefinition, type BaseServerConfig, BaseServerProvider, BasicJsonSchema, type CapabilityRecord, CustomEndpointError, type CustomEndpointHandler, DEFAULT_A2A_ROUTE_PREFIX, DEFAULT_A2A_WELL_KNOWN_PREFIX, DEFAULT_MCP_HTTP_SEGMENT, DEFAULT_MCP_MESSAGES_SEGMENT, DEFAULT_MCP_ROUTE_PREFIX, DEFAULT_MCP_SSE_SEGMENT, DEFAULT_PUBLIC_ROUTES, ErrorSchema, type FilterContext, GenerateOptionsSchema, HttpMethod, type IWebSocket, type JWTAuthOptions, type LogStreamClient, LogStreamManager, type MCPAgentMetadata, type MCPListedTool, type MCPServerCapabilitiesConfig, type MCPServerLike, type MCPServerMetadata, type MCPServerPackageInfo, type MCPServerRemoteInfo, type MCPToolMetadata, type MCPToolOrigin, type MCPWorkflowSummary, MCP_SESSION_QUERY_PARAM, type McpInvokeToolRequest, type McpInvokeToolResponse, type McpPromptDetailResponse, type McpPromptListResponse, type McpResourceDetailResponse, type McpResourceListResponse, type McpResourceTemplateListResponse, type McpRouteOptions, type McpRoutePaths, type McpServerDetailResponse, type McpServerListResponse, type McpServerLookupResult, McpSessionStore, type McpSetLogLevelRequest, type McpSetLogLevelResponse, type McpToolListResponse, ObjectRequestSchema, ObjectResponseSchema, PROTECTED_ROUTES, ParamsSchema, type PortConfig, type ProcessedAgentOptions, type ProtocolConfig, type ProtocolRecord, type ServerEndpointSummary, type ServerProviderConfig, type ServerStartupOptions, StreamObjectEventSchema, StreamTextEventSchema, SubAgentResponseSchema, TextRequestSchema, TextResponseSchema, type WebSocketAdapter, type WebSocketConnectionHandler, type WebSocketConnectionInfo, type WebSocketEventHandlers, type WebSocketMessage, WebSocketRouter, WorkflowCancelRequestSchema, WorkflowCancelResponseSchema, WorkflowExecutionParamsSchema, WorkflowExecutionRequestSchema, WorkflowExecutionResponseSchema, WorkflowListSchema, WorkflowParamsSchema, WorkflowResponseSchema, WorkflowResumeRequestSchema, WorkflowResumeResponseSchema, WorkflowStreamEventSchema, WorkflowSuspendRequestSchema, WorkflowSuspendResponseSchema, buildA2AEndpointPath, buildAgentCardPath, buildMcpRoutePaths, cleanupWebSockets, closeAllObservabilityConnections, colors, createAuthErrorResponse, createJWT, createSSEHeaders, createSSEResponse, createSSEStream, createUserContext, createWebSocketRouter, createWebSocketServer, extractBearerToken, extractToken, formatSSE, getLandingPageHTML, getLogsBySpanIdHandler, getLogsByTraceIdHandler, getObservabilityStatusHandler, getPortsToTry, getSpanByIdHandler, getTraceByIdHandler, getTracesHandler, handleCheckUpdates, handleGetMcpPrompt, handleGetMcpResource, handleGetMcpServer, handleInstallUpdates, handleInvokeMcpServerTool, handleListMcpPrompts, handleListMcpResourceTemplates, handleListMcpResources, handleListMcpServerTools, handleListMcpServers, handleObservabilityConnection, handleSetMcpLogLevel, handleWebSocketConnection, injectUserIntoBody, jwtAuth, listA2AServers, listMcpServers, lookupA2AServer, lookupMcpServer, pathMatches, portManager, preferredPorts, printServerStartup, processAgentOptions, processWorkflowOptions, queryLogsHandler, requiresAuth, setupObservabilityHandler, setupObservabilityListeners, setupWebSocketUpgrade, transformToSSE, validateBaseCustomEndpoint, validateEndpointMethod, validateEndpointPath };
|
package/dist/index.d.ts
CHANGED
|
@@ -1345,6 +1345,26 @@ interface AuthProvider<TRequest = any> {
|
|
|
1345
1345
|
* These are added to the default public routes
|
|
1346
1346
|
*/
|
|
1347
1347
|
publicRoutes?: string[];
|
|
1348
|
+
/**
|
|
1349
|
+
* When true, all routes require authentication by default (opt-out model)
|
|
1350
|
+
* When false or undefined, only routes in PROTECTED_ROUTES require auth (opt-in model)
|
|
1351
|
+
*
|
|
1352
|
+
* Use this when you want to protect all routes by default and selectively
|
|
1353
|
+
* make certain routes public using the publicRoutes property.
|
|
1354
|
+
*
|
|
1355
|
+
* @default false
|
|
1356
|
+
* @example
|
|
1357
|
+
* ```typescript
|
|
1358
|
+
* // Protect all routes except those in publicRoutes
|
|
1359
|
+
* const authProvider: AuthProvider = {
|
|
1360
|
+
* type: 'clerk',
|
|
1361
|
+
* defaultPrivate: true,
|
|
1362
|
+
* publicRoutes: ['GET /health', 'POST /webhooks'],
|
|
1363
|
+
* verifyToken: async (token) => { ... }
|
|
1364
|
+
* }
|
|
1365
|
+
* ```
|
|
1366
|
+
*/
|
|
1367
|
+
defaultPrivate?: boolean;
|
|
1348
1368
|
}
|
|
1349
1369
|
|
|
1350
1370
|
/**
|
|
@@ -1372,63 +1392,10 @@ declare function pathMatches(path: string, pattern: string): boolean;
|
|
|
1372
1392
|
* @param method The HTTP method
|
|
1373
1393
|
* @param path The request path
|
|
1374
1394
|
* @param publicRoutes Additional public routes from config
|
|
1395
|
+
* @param defaultPrivate When true, routes require auth by default (opt-out model)
|
|
1375
1396
|
* @returns True if the route requires authentication
|
|
1376
1397
|
*/
|
|
1377
|
-
declare function requiresAuth(method: string, path: string, publicRoutes?: string[]): boolean;
|
|
1378
|
-
|
|
1379
|
-
/**
|
|
1380
|
-
* Framework-agnostic authentication middleware factory
|
|
1381
|
-
*/
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* Framework adapter for authentication middleware
|
|
1385
|
-
* Each framework implements this interface to bridge framework-specific APIs
|
|
1386
|
-
*/
|
|
1387
|
-
interface AuthFrameworkAdapter<TRequest, TResponse> {
|
|
1388
|
-
/**
|
|
1389
|
-
* Get the request path
|
|
1390
|
-
*/
|
|
1391
|
-
getPath(req: TRequest): string;
|
|
1392
|
-
/**
|
|
1393
|
-
* Get the request method
|
|
1394
|
-
*/
|
|
1395
|
-
getMethod(req: TRequest): string;
|
|
1396
|
-
/**
|
|
1397
|
-
* Get a request header
|
|
1398
|
-
*/
|
|
1399
|
-
getHeader(req: TRequest, name: string): string | undefined;
|
|
1400
|
-
/**
|
|
1401
|
-
* Get the raw request object (for providers that need it)
|
|
1402
|
-
*/
|
|
1403
|
-
getRawRequest(req: TRequest): Request;
|
|
1404
|
-
/**
|
|
1405
|
-
* Get the request body
|
|
1406
|
-
*/
|
|
1407
|
-
getBody(req: TRequest): Promise<any>;
|
|
1408
|
-
/**
|
|
1409
|
-
* Set authenticated user in the context
|
|
1410
|
-
*/
|
|
1411
|
-
setUser(context: any, user: any): void;
|
|
1412
|
-
/**
|
|
1413
|
-
* Modify request body to include user context
|
|
1414
|
-
*/
|
|
1415
|
-
injectUserIntoBody(req: TRequest, user: any): void;
|
|
1416
|
-
/**
|
|
1417
|
-
* Send an error response
|
|
1418
|
-
*/
|
|
1419
|
-
sendError(res: TResponse, message: string, status: number): any;
|
|
1420
|
-
/**
|
|
1421
|
-
* Send success to next middleware
|
|
1422
|
-
*/
|
|
1423
|
-
next(): any;
|
|
1424
|
-
}
|
|
1425
|
-
/**
|
|
1426
|
-
* Create authentication middleware with framework adapter
|
|
1427
|
-
* @param authProvider The authentication provider
|
|
1428
|
-
* @param adapter Framework-specific adapter
|
|
1429
|
-
* @returns Middleware function for the framework
|
|
1430
|
-
*/
|
|
1431
|
-
declare function createAuthMiddlewareFactory<TRequest, TResponse>(authProvider: AuthProvider<Request>, adapter: AuthFrameworkAdapter<TRequest, TResponse>): (req: TRequest, res: TResponse, next?: () => any) => Promise<any>;
|
|
1398
|
+
declare function requiresAuth(method: string, path: string, publicRoutes?: string[], defaultPrivate?: boolean): boolean;
|
|
1432
1399
|
|
|
1433
1400
|
/**
|
|
1434
1401
|
* JWT authentication options
|
|
@@ -1904,4 +1871,4 @@ declare abstract class BaseServerProvider implements IServerProvider {
|
|
|
1904
1871
|
private collectFeatureEndpoints;
|
|
1905
1872
|
}
|
|
1906
1873
|
|
|
1907
|
-
export { A2AServerLikeWithHandlers, type A2AServerLookupResult, AgentListSchema, AgentParamsSchema, AgentResponseSchema, ApiResponse, type
|
|
1874
|
+
export { A2AServerLikeWithHandlers, type A2AServerLookupResult, AgentListSchema, AgentParamsSchema, AgentResponseSchema, ApiResponse, type AuthProvider, type BaseCustomEndpointDefinition, type BaseServerConfig, BaseServerProvider, BasicJsonSchema, type CapabilityRecord, CustomEndpointError, type CustomEndpointHandler, DEFAULT_A2A_ROUTE_PREFIX, DEFAULT_A2A_WELL_KNOWN_PREFIX, DEFAULT_MCP_HTTP_SEGMENT, DEFAULT_MCP_MESSAGES_SEGMENT, DEFAULT_MCP_ROUTE_PREFIX, DEFAULT_MCP_SSE_SEGMENT, DEFAULT_PUBLIC_ROUTES, ErrorSchema, type FilterContext, GenerateOptionsSchema, HttpMethod, type IWebSocket, type JWTAuthOptions, type LogStreamClient, LogStreamManager, type MCPAgentMetadata, type MCPListedTool, type MCPServerCapabilitiesConfig, type MCPServerLike, type MCPServerMetadata, type MCPServerPackageInfo, type MCPServerRemoteInfo, type MCPToolMetadata, type MCPToolOrigin, type MCPWorkflowSummary, MCP_SESSION_QUERY_PARAM, type McpInvokeToolRequest, type McpInvokeToolResponse, type McpPromptDetailResponse, type McpPromptListResponse, type McpResourceDetailResponse, type McpResourceListResponse, type McpResourceTemplateListResponse, type McpRouteOptions, type McpRoutePaths, type McpServerDetailResponse, type McpServerListResponse, type McpServerLookupResult, McpSessionStore, type McpSetLogLevelRequest, type McpSetLogLevelResponse, type McpToolListResponse, ObjectRequestSchema, ObjectResponseSchema, PROTECTED_ROUTES, ParamsSchema, type PortConfig, type ProcessedAgentOptions, type ProtocolConfig, type ProtocolRecord, type ServerEndpointSummary, type ServerProviderConfig, type ServerStartupOptions, StreamObjectEventSchema, StreamTextEventSchema, SubAgentResponseSchema, TextRequestSchema, TextResponseSchema, type WebSocketAdapter, type WebSocketConnectionHandler, type WebSocketConnectionInfo, type WebSocketEventHandlers, type WebSocketMessage, WebSocketRouter, WorkflowCancelRequestSchema, WorkflowCancelResponseSchema, WorkflowExecutionParamsSchema, WorkflowExecutionRequestSchema, WorkflowExecutionResponseSchema, WorkflowListSchema, WorkflowParamsSchema, WorkflowResponseSchema, WorkflowResumeRequestSchema, WorkflowResumeResponseSchema, WorkflowStreamEventSchema, WorkflowSuspendRequestSchema, WorkflowSuspendResponseSchema, buildA2AEndpointPath, buildAgentCardPath, buildMcpRoutePaths, cleanupWebSockets, closeAllObservabilityConnections, colors, createAuthErrorResponse, createJWT, createSSEHeaders, createSSEResponse, createSSEStream, createUserContext, createWebSocketRouter, createWebSocketServer, extractBearerToken, extractToken, formatSSE, getLandingPageHTML, getLogsBySpanIdHandler, getLogsByTraceIdHandler, getObservabilityStatusHandler, getPortsToTry, getSpanByIdHandler, getTraceByIdHandler, getTracesHandler, handleCheckUpdates, handleGetMcpPrompt, handleGetMcpResource, handleGetMcpServer, handleInstallUpdates, handleInvokeMcpServerTool, handleListMcpPrompts, handleListMcpResourceTemplates, handleListMcpResources, handleListMcpServerTools, handleListMcpServers, handleObservabilityConnection, handleSetMcpLogLevel, handleWebSocketConnection, injectUserIntoBody, jwtAuth, listA2AServers, listMcpServers, lookupA2AServer, lookupMcpServer, pathMatches, portManager, preferredPorts, printServerStartup, processAgentOptions, processWorkflowOptions, queryLogsHandler, requiresAuth, setupObservabilityHandler, setupObservabilityListeners, setupWebSocketUpgrade, transformToSSE, validateBaseCustomEndpoint, validateEndpointMethod, validateEndpointPath };
|
package/dist/index.js
CHANGED
|
@@ -91,7 +91,6 @@ __export(index_exports, {
|
|
|
91
91
|
closeAllObservabilityConnections: () => closeAllObservabilityConnections,
|
|
92
92
|
colors: () => colors,
|
|
93
93
|
createAuthErrorResponse: () => createAuthErrorResponse,
|
|
94
|
-
createAuthMiddlewareFactory: () => createAuthMiddlewareFactory,
|
|
95
94
|
createJWT: () => createJWT,
|
|
96
95
|
createSSEHeaders: () => createSSEHeaders,
|
|
97
96
|
createSSEResponse: () => createSSEResponse,
|
|
@@ -3471,7 +3470,7 @@ function pathMatches(path2, pattern) {
|
|
|
3471
3470
|
return true;
|
|
3472
3471
|
}
|
|
3473
3472
|
__name(pathMatches, "pathMatches");
|
|
3474
|
-
function requiresAuth(method, path2, publicRoutes) {
|
|
3473
|
+
function requiresAuth(method, path2, publicRoutes, defaultPrivate) {
|
|
3475
3474
|
const fullRoute = `${method.toUpperCase()} ${path2}`;
|
|
3476
3475
|
for (const publicRoute of DEFAULT_PUBLIC_ROUTES) {
|
|
3477
3476
|
if (publicRoute.includes(" ")) {
|
|
@@ -3509,46 +3508,10 @@ function requiresAuth(method, path2, publicRoutes) {
|
|
|
3509
3508
|
}
|
|
3510
3509
|
}
|
|
3511
3510
|
}
|
|
3512
|
-
return false;
|
|
3511
|
+
return defaultPrivate ?? false;
|
|
3513
3512
|
}
|
|
3514
3513
|
__name(requiresAuth, "requiresAuth");
|
|
3515
3514
|
|
|
3516
|
-
// src/auth/middleware-factory.ts
|
|
3517
|
-
function createAuthMiddlewareFactory(authProvider, adapter) {
|
|
3518
|
-
return async (req, res, next) => {
|
|
3519
|
-
const path2 = adapter.getPath(req);
|
|
3520
|
-
const method = adapter.getMethod(req);
|
|
3521
|
-
if (!requiresAuth(method, path2, authProvider.publicRoutes)) {
|
|
3522
|
-
return next ? next() : adapter.next();
|
|
3523
|
-
}
|
|
3524
|
-
try {
|
|
3525
|
-
let token;
|
|
3526
|
-
if (authProvider.extractToken) {
|
|
3527
|
-
token = authProvider.extractToken(adapter.getRawRequest(req));
|
|
3528
|
-
} else {
|
|
3529
|
-
const authHeader = adapter.getHeader(req, "Authorization");
|
|
3530
|
-
if (authHeader?.startsWith("Bearer ")) {
|
|
3531
|
-
token = authHeader.substring(7);
|
|
3532
|
-
}
|
|
3533
|
-
}
|
|
3534
|
-
if (!token) {
|
|
3535
|
-
return adapter.sendError(res, "Authentication required", 401);
|
|
3536
|
-
}
|
|
3537
|
-
const user = await authProvider.verifyToken(token, adapter.getRawRequest(req));
|
|
3538
|
-
if (!user) {
|
|
3539
|
-
return adapter.sendError(res, "Invalid authentication", 401);
|
|
3540
|
-
}
|
|
3541
|
-
adapter.setUser(req, user);
|
|
3542
|
-
adapter.injectUserIntoBody(req, user);
|
|
3543
|
-
return next ? next() : adapter.next();
|
|
3544
|
-
} catch (error) {
|
|
3545
|
-
const message = error instanceof Error ? error.message : "Authentication failed";
|
|
3546
|
-
return adapter.sendError(res, message, 401);
|
|
3547
|
-
}
|
|
3548
|
-
};
|
|
3549
|
-
}
|
|
3550
|
-
__name(createAuthMiddlewareFactory, "createAuthMiddlewareFactory");
|
|
3551
|
-
|
|
3552
3515
|
// src/auth/providers/jwt.ts
|
|
3553
3516
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
3554
3517
|
function jwtAuth(options) {
|
|
@@ -4730,7 +4693,6 @@ var DEFAULT_CORS_OPTIONS = {
|
|
|
4730
4693
|
closeAllObservabilityConnections,
|
|
4731
4694
|
colors,
|
|
4732
4695
|
createAuthErrorResponse,
|
|
4733
|
-
createAuthMiddlewareFactory,
|
|
4734
4696
|
createJWT,
|
|
4735
4697
|
createSSEHeaders,
|
|
4736
4698
|
createSSEResponse,
|