@relayrail/server 0.1.3 → 0.1.5
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/cli.js +85 -2
- package/dist/index.d.ts +58 -2
- package/dist/index.js +83 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1497,6 +1497,81 @@ function createRouter(config, supabase) {
|
|
|
1497
1497
|
return new RequestRouter(config, supabase);
|
|
1498
1498
|
}
|
|
1499
1499
|
|
|
1500
|
+
// src/services/proxy-router.ts
|
|
1501
|
+
var ProxyRouter = class {
|
|
1502
|
+
apiUrl;
|
|
1503
|
+
apiKey;
|
|
1504
|
+
constructor(config) {
|
|
1505
|
+
this.apiUrl = config.apiUrl.replace(/\/$/, "");
|
|
1506
|
+
this.apiKey = config.apiKey;
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Route an approval request via the API
|
|
1510
|
+
* @param params - Approval parameters
|
|
1511
|
+
* @param _user - User (unused, API handles lookup)
|
|
1512
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
1513
|
+
*/
|
|
1514
|
+
async routeApproval(params, _user, _agent) {
|
|
1515
|
+
return this.sendViaApi(params.requestId, "approval");
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Route a notification via the API
|
|
1519
|
+
* @param params - Notification parameters
|
|
1520
|
+
* @param _user - User (unused, API handles lookup)
|
|
1521
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
1522
|
+
*/
|
|
1523
|
+
async routeNotification(params, _user, _agent) {
|
|
1524
|
+
return this.sendViaApi(params.requestId, "notification");
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* Send a message via the RelayRail API
|
|
1528
|
+
*/
|
|
1529
|
+
async sendViaApi(requestId, type) {
|
|
1530
|
+
try {
|
|
1531
|
+
const response = await fetch(`${this.apiUrl}/api/send-message`, {
|
|
1532
|
+
method: "POST",
|
|
1533
|
+
headers: {
|
|
1534
|
+
"Content-Type": "application/json",
|
|
1535
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
1536
|
+
},
|
|
1537
|
+
body: JSON.stringify({
|
|
1538
|
+
request_id: requestId,
|
|
1539
|
+
type
|
|
1540
|
+
})
|
|
1541
|
+
});
|
|
1542
|
+
const data = await response.json();
|
|
1543
|
+
if (!response.ok) {
|
|
1544
|
+
console.error(`[ProxyRouter] API error:`, data);
|
|
1545
|
+
return {
|
|
1546
|
+
success: false,
|
|
1547
|
+
channel: "email",
|
|
1548
|
+
error: data.error || `API error: ${response.status}`
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
return {
|
|
1552
|
+
success: data.success,
|
|
1553
|
+
channel: data.channel || "email",
|
|
1554
|
+
channel_requested: data.channel_requested,
|
|
1555
|
+
fallback_reason: data.fallback_reason,
|
|
1556
|
+
messageId: data.message_id,
|
|
1557
|
+
error: data.error,
|
|
1558
|
+
quota: data.quota,
|
|
1559
|
+
quotaError: data.quota_error
|
|
1560
|
+
};
|
|
1561
|
+
} catch (error) {
|
|
1562
|
+
console.error(`[ProxyRouter] Network error:`, error);
|
|
1563
|
+
return {
|
|
1564
|
+
success: false,
|
|
1565
|
+
channel: "email",
|
|
1566
|
+
error: error instanceof Error ? error.message : "Network error"
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
function createProxyRouter(config) {
|
|
1572
|
+
return new ProxyRouter(config);
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1500
1575
|
// src/server.ts
|
|
1501
1576
|
var VERSION = "0.1.0";
|
|
1502
1577
|
var RelayRailServer = class {
|
|
@@ -1529,6 +1604,12 @@ var RelayRailServer = class {
|
|
|
1529
1604
|
},
|
|
1530
1605
|
this.supabase
|
|
1531
1606
|
);
|
|
1607
|
+
} else if (config.apiKey) {
|
|
1608
|
+
console.log("[RelayRail] Using proxy router for message delivery");
|
|
1609
|
+
this.router = createProxyRouter({
|
|
1610
|
+
apiUrl: config.baseUrl,
|
|
1611
|
+
apiKey: config.apiKey
|
|
1612
|
+
});
|
|
1532
1613
|
}
|
|
1533
1614
|
this.server = new McpServer({
|
|
1534
1615
|
name: "relayrail",
|
|
@@ -1849,10 +1930,12 @@ async function main() {
|
|
|
1849
1930
|
const config = {
|
|
1850
1931
|
supabaseUrl: process.env.SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL || "https://lcmdokppykqmigqcwnol.supabase.co",
|
|
1851
1932
|
supabaseServiceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY || "sb_secret_cj-1Y1KxjlapuwyXvfSKLA_xBJ0oS8i",
|
|
1852
|
-
baseUrl: process.env.RELAYRAIL_BASE_URL || "https://relayrail.dev",
|
|
1933
|
+
baseUrl: process.env.RELAYRAIL_BASE_URL || "https://www.relayrail.dev",
|
|
1853
1934
|
resendApiKey: process.env.RESEND_API_KEY,
|
|
1854
1935
|
telnyxApiKey: process.env.TELNYX_API_KEY,
|
|
1855
|
-
telnyxPhoneNumber: process.env.TELNYX_PHONE_NUMBER
|
|
1936
|
+
telnyxPhoneNumber: process.env.TELNYX_PHONE_NUMBER,
|
|
1937
|
+
apiKey
|
|
1938
|
+
// Used for proxy routing when local email/SMS credentials unavailable
|
|
1856
1939
|
};
|
|
1857
1940
|
try {
|
|
1858
1941
|
const server = createServer(config);
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ interface ServerConfig {
|
|
|
22
22
|
telnyxPhoneNumber?: string;
|
|
23
23
|
/** Base URL for response pages */
|
|
24
24
|
baseUrl: string;
|
|
25
|
+
/** API key for proxy mode (when email/SMS credentials unavailable locally) */
|
|
26
|
+
apiKey?: string;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Context passed to tool handlers
|
|
@@ -379,11 +381,19 @@ interface RouteResult {
|
|
|
379
381
|
/** Quota error if send was blocked */
|
|
380
382
|
quotaError?: QuotaError;
|
|
381
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Common interface for message routing
|
|
386
|
+
* Implemented by both RequestRouter (direct sending) and ProxyRouter (API proxy)
|
|
387
|
+
*/
|
|
388
|
+
interface MessageRouter {
|
|
389
|
+
routeApproval(params: RouteApprovalParams, user: User, agent: Agent): Promise<RouteResult>;
|
|
390
|
+
routeNotification(params: RouteNotificationParams, user: User, agent: Agent): Promise<RouteResult>;
|
|
391
|
+
}
|
|
382
392
|
/**
|
|
383
393
|
* Request router that sends requests via the appropriate channel
|
|
384
394
|
* with quota enforcement and overage billing
|
|
385
395
|
*/
|
|
386
|
-
declare class RequestRouter {
|
|
396
|
+
declare class RequestRouter implements MessageRouter {
|
|
387
397
|
private emailService;
|
|
388
398
|
private smsService?;
|
|
389
399
|
private usageService;
|
|
@@ -412,6 +422,10 @@ declare class RequestRouter {
|
|
|
412
422
|
*/
|
|
413
423
|
private createQuotaErrorResult;
|
|
414
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Create a request router instance
|
|
427
|
+
*/
|
|
428
|
+
declare function createRouter(config: RouterConfig, supabase: TypedSupabaseClient): RequestRouter;
|
|
415
429
|
|
|
416
430
|
/**
|
|
417
431
|
* HTTP Transport for MCP Server
|
|
@@ -504,4 +518,46 @@ declare class HTTPTransport {
|
|
|
504
518
|
*/
|
|
505
519
|
declare function createHTTPTransport(config: HTTPTransportConfig): HTTPTransport;
|
|
506
520
|
|
|
507
|
-
|
|
521
|
+
/**
|
|
522
|
+
* Proxy Router
|
|
523
|
+
* Routes requests to the hosted RelayRail API for message sending
|
|
524
|
+
* Used when local email/SMS credentials are not available
|
|
525
|
+
*/
|
|
526
|
+
|
|
527
|
+
interface ProxyRouterConfig {
|
|
528
|
+
apiUrl: string;
|
|
529
|
+
apiKey: string;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Proxy router that sends messages via the RelayRail API
|
|
533
|
+
* Implements the same interface as RequestRouter for drop-in replacement
|
|
534
|
+
*/
|
|
535
|
+
declare class ProxyRouter implements MessageRouter {
|
|
536
|
+
private apiUrl;
|
|
537
|
+
private apiKey;
|
|
538
|
+
constructor(config: ProxyRouterConfig);
|
|
539
|
+
/**
|
|
540
|
+
* Route an approval request via the API
|
|
541
|
+
* @param params - Approval parameters
|
|
542
|
+
* @param _user - User (unused, API handles lookup)
|
|
543
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
544
|
+
*/
|
|
545
|
+
routeApproval(params: RouteApprovalParams, _user: User, _agent: Agent): Promise<RouteResult>;
|
|
546
|
+
/**
|
|
547
|
+
* Route a notification via the API
|
|
548
|
+
* @param params - Notification parameters
|
|
549
|
+
* @param _user - User (unused, API handles lookup)
|
|
550
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
551
|
+
*/
|
|
552
|
+
routeNotification(params: RouteNotificationParams, _user: User, _agent: Agent): Promise<RouteResult>;
|
|
553
|
+
/**
|
|
554
|
+
* Send a message via the RelayRail API
|
|
555
|
+
*/
|
|
556
|
+
private sendViaApi;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Create a proxy router instance
|
|
560
|
+
*/
|
|
561
|
+
declare function createProxyRouter(config: ProxyRouterConfig): ProxyRouter;
|
|
562
|
+
|
|
563
|
+
export { type ApprovalRequestParams, type ApprovalResponse, type AuthResult, type AwaitResponseParams, type AwaitResult, type GetPendingCommandsParams, HTTPTransport, type HTTPTransportConfig, type MCPNotification, type MCPRequest, type MCPResponse, MCP_ERRORS, type MessageRouter, type NotificationParams, type NotificationResponse, ProxyRouter, type ProxyRouterConfig, RelayRailServer, RequestRouter, type RouteApprovalParams, type RouteNotificationParams, type RouteResult, type RouterConfig, type ServerConfig, type ToolContext, type UserCommand, VERSION, authenticateApiKey, createHTTPTransport, createProxyRouter, createRouter, createServer, generateApiKey, getApiKeyPrefix, hashApiKey };
|
package/dist/index.js
CHANGED
|
@@ -1495,6 +1495,81 @@ function createRouter(config, supabase) {
|
|
|
1495
1495
|
return new RequestRouter(config, supabase);
|
|
1496
1496
|
}
|
|
1497
1497
|
|
|
1498
|
+
// src/services/proxy-router.ts
|
|
1499
|
+
var ProxyRouter = class {
|
|
1500
|
+
apiUrl;
|
|
1501
|
+
apiKey;
|
|
1502
|
+
constructor(config) {
|
|
1503
|
+
this.apiUrl = config.apiUrl.replace(/\/$/, "");
|
|
1504
|
+
this.apiKey = config.apiKey;
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Route an approval request via the API
|
|
1508
|
+
* @param params - Approval parameters
|
|
1509
|
+
* @param _user - User (unused, API handles lookup)
|
|
1510
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
1511
|
+
*/
|
|
1512
|
+
async routeApproval(params, _user, _agent) {
|
|
1513
|
+
return this.sendViaApi(params.requestId, "approval");
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Route a notification via the API
|
|
1517
|
+
* @param params - Notification parameters
|
|
1518
|
+
* @param _user - User (unused, API handles lookup)
|
|
1519
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
1520
|
+
*/
|
|
1521
|
+
async routeNotification(params, _user, _agent) {
|
|
1522
|
+
return this.sendViaApi(params.requestId, "notification");
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Send a message via the RelayRail API
|
|
1526
|
+
*/
|
|
1527
|
+
async sendViaApi(requestId, type) {
|
|
1528
|
+
try {
|
|
1529
|
+
const response = await fetch(`${this.apiUrl}/api/send-message`, {
|
|
1530
|
+
method: "POST",
|
|
1531
|
+
headers: {
|
|
1532
|
+
"Content-Type": "application/json",
|
|
1533
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
1534
|
+
},
|
|
1535
|
+
body: JSON.stringify({
|
|
1536
|
+
request_id: requestId,
|
|
1537
|
+
type
|
|
1538
|
+
})
|
|
1539
|
+
});
|
|
1540
|
+
const data = await response.json();
|
|
1541
|
+
if (!response.ok) {
|
|
1542
|
+
console.error(`[ProxyRouter] API error:`, data);
|
|
1543
|
+
return {
|
|
1544
|
+
success: false,
|
|
1545
|
+
channel: "email",
|
|
1546
|
+
error: data.error || `API error: ${response.status}`
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
return {
|
|
1550
|
+
success: data.success,
|
|
1551
|
+
channel: data.channel || "email",
|
|
1552
|
+
channel_requested: data.channel_requested,
|
|
1553
|
+
fallback_reason: data.fallback_reason,
|
|
1554
|
+
messageId: data.message_id,
|
|
1555
|
+
error: data.error,
|
|
1556
|
+
quota: data.quota,
|
|
1557
|
+
quotaError: data.quota_error
|
|
1558
|
+
};
|
|
1559
|
+
} catch (error) {
|
|
1560
|
+
console.error(`[ProxyRouter] Network error:`, error);
|
|
1561
|
+
return {
|
|
1562
|
+
success: false,
|
|
1563
|
+
channel: "email",
|
|
1564
|
+
error: error instanceof Error ? error.message : "Network error"
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
function createProxyRouter(config) {
|
|
1570
|
+
return new ProxyRouter(config);
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1498
1573
|
// src/server.ts
|
|
1499
1574
|
var VERSION = "0.1.0";
|
|
1500
1575
|
var RelayRailServer = class {
|
|
@@ -1527,6 +1602,12 @@ var RelayRailServer = class {
|
|
|
1527
1602
|
},
|
|
1528
1603
|
this.supabase
|
|
1529
1604
|
);
|
|
1605
|
+
} else if (config.apiKey) {
|
|
1606
|
+
console.log("[RelayRail] Using proxy router for message delivery");
|
|
1607
|
+
this.router = createProxyRouter({
|
|
1608
|
+
apiUrl: config.baseUrl,
|
|
1609
|
+
apiKey: config.apiKey
|
|
1610
|
+
});
|
|
1530
1611
|
}
|
|
1531
1612
|
this.server = new McpServer({
|
|
1532
1613
|
name: "relayrail",
|
|
@@ -2204,6 +2285,8 @@ export {
|
|
|
2204
2285
|
VERSION,
|
|
2205
2286
|
authenticateApiKey,
|
|
2206
2287
|
createHTTPTransport,
|
|
2288
|
+
createProxyRouter,
|
|
2289
|
+
createRouter,
|
|
2207
2290
|
createServer,
|
|
2208
2291
|
generateApiKey,
|
|
2209
2292
|
getApiKeyPrefix,
|