@willjackson/claude-code-bridge 0.6.2 → 0.7.0
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/{chunk-XOAR3DQB.js → chunk-2O352EPO.js} +745 -154
- package/dist/chunk-2O352EPO.js.map +1 -0
- package/dist/cli.js +96 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +421 -112
- package/dist/index.js +26 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-XOAR3DQB.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import pino from 'pino';
|
|
3
|
+
import * as tls from 'tls';
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Protocol definitions for Claude Code Bridge
|
|
@@ -516,6 +518,142 @@ declare function safeDeserializeMessage(json: string): z.SafeParseSuccess<{
|
|
|
516
518
|
error: z.ZodError<any>;
|
|
517
519
|
};
|
|
518
520
|
|
|
521
|
+
/**
|
|
522
|
+
* Transport layer interface and types for Claude Code Bridge
|
|
523
|
+
* Defines the abstract transport interface for communication between bridge instances
|
|
524
|
+
*/
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Represents the current state of a transport connection
|
|
528
|
+
*/
|
|
529
|
+
declare enum ConnectionState {
|
|
530
|
+
/** Not connected to any peer */
|
|
531
|
+
DISCONNECTED = "DISCONNECTED",
|
|
532
|
+
/** Currently attempting to establish connection */
|
|
533
|
+
CONNECTING = "CONNECTING",
|
|
534
|
+
/** Successfully connected and ready for communication */
|
|
535
|
+
CONNECTED = "CONNECTED",
|
|
536
|
+
/** Connection lost, attempting to reconnect */
|
|
537
|
+
RECONNECTING = "RECONNECTING"
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* TLS configuration for secure connections
|
|
541
|
+
*/
|
|
542
|
+
interface TLSConfig$2 {
|
|
543
|
+
/** Path to certificate PEM file (for server) */
|
|
544
|
+
cert?: string;
|
|
545
|
+
/** Path to private key PEM file (for server) */
|
|
546
|
+
key?: string;
|
|
547
|
+
/** Path to CA certificate PEM file (for client to verify server, or server to verify client) */
|
|
548
|
+
ca?: string;
|
|
549
|
+
/** Whether to reject unauthorized certificates (default: true) */
|
|
550
|
+
rejectUnauthorized?: boolean;
|
|
551
|
+
/** Passphrase for encrypted private key */
|
|
552
|
+
passphrase?: string;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Authentication type
|
|
556
|
+
*/
|
|
557
|
+
type AuthType$2 = 'none' | 'token' | 'password' | 'ip' | 'combined';
|
|
558
|
+
/**
|
|
559
|
+
* Authentication configuration for transport connections
|
|
560
|
+
*/
|
|
561
|
+
interface AuthConfig$2 {
|
|
562
|
+
/** Authentication type */
|
|
563
|
+
type: AuthType$2;
|
|
564
|
+
/** Authentication token (for type: 'token' or 'combined') */
|
|
565
|
+
token?: string;
|
|
566
|
+
/** Authentication password (for type: 'password' or 'combined') */
|
|
567
|
+
password?: string;
|
|
568
|
+
/** Allowed IP addresses/ranges in CIDR notation (for type: 'ip' or 'combined') */
|
|
569
|
+
allowedIps?: string[];
|
|
570
|
+
/** If true, ALL configured methods must pass; if false, ANY passing method is sufficient */
|
|
571
|
+
requireAll?: boolean;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Configuration for establishing a transport connection
|
|
575
|
+
*/
|
|
576
|
+
interface ConnectionConfig {
|
|
577
|
+
/** Full WebSocket URL (e.g., ws://localhost:8765 or wss://localhost:8765) */
|
|
578
|
+
url?: string;
|
|
579
|
+
/** Host to connect to (used if url is not provided) */
|
|
580
|
+
host?: string;
|
|
581
|
+
/** Port to connect to (used if url is not provided) */
|
|
582
|
+
port?: number;
|
|
583
|
+
/** Enable automatic reconnection on disconnect */
|
|
584
|
+
reconnect?: boolean;
|
|
585
|
+
/** Interval between reconnection attempts in milliseconds */
|
|
586
|
+
reconnectInterval?: number;
|
|
587
|
+
/** Maximum number of reconnection attempts before giving up */
|
|
588
|
+
maxReconnectAttempts?: number;
|
|
589
|
+
/** Authentication configuration */
|
|
590
|
+
auth?: AuthConfig$2;
|
|
591
|
+
/** TLS configuration for secure connections */
|
|
592
|
+
tls?: TLSConfig$2;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Handler for incoming messages
|
|
596
|
+
*/
|
|
597
|
+
type MessageHandler = (message: BridgeMessage) => void;
|
|
598
|
+
/**
|
|
599
|
+
* Handler for disconnect events
|
|
600
|
+
*/
|
|
601
|
+
type DisconnectHandler = () => void;
|
|
602
|
+
/**
|
|
603
|
+
* Handler for error events
|
|
604
|
+
*/
|
|
605
|
+
type ErrorHandler = (error: Error) => void;
|
|
606
|
+
/**
|
|
607
|
+
* Abstract transport interface for bridge communication
|
|
608
|
+
* Implementations handle the actual network protocol (WebSocket, TCP, etc.)
|
|
609
|
+
*/
|
|
610
|
+
interface Transport {
|
|
611
|
+
/**
|
|
612
|
+
* Establish connection to a remote peer
|
|
613
|
+
* @param config Connection configuration
|
|
614
|
+
* @returns Promise that resolves when connection is established
|
|
615
|
+
* @throws Error if connection fails
|
|
616
|
+
*/
|
|
617
|
+
connect(config: ConnectionConfig): Promise<void>;
|
|
618
|
+
/**
|
|
619
|
+
* Cleanly close the current connection
|
|
620
|
+
* @returns Promise that resolves when disconnection is complete
|
|
621
|
+
*/
|
|
622
|
+
disconnect(): Promise<void>;
|
|
623
|
+
/**
|
|
624
|
+
* Send a message to the connected peer
|
|
625
|
+
* @param message The message to send
|
|
626
|
+
* @returns Promise that resolves when message is sent
|
|
627
|
+
* @throws Error if not connected and message cannot be queued
|
|
628
|
+
*/
|
|
629
|
+
send(message: BridgeMessage): Promise<void>;
|
|
630
|
+
/**
|
|
631
|
+
* Register a handler for incoming messages
|
|
632
|
+
* @param handler Function to call when a message is received
|
|
633
|
+
*/
|
|
634
|
+
onMessage(handler: MessageHandler): void;
|
|
635
|
+
/**
|
|
636
|
+
* Register a handler for disconnect events
|
|
637
|
+
* @param handler Function to call when connection is lost
|
|
638
|
+
*/
|
|
639
|
+
onDisconnect(handler: DisconnectHandler): void;
|
|
640
|
+
/**
|
|
641
|
+
* Register a handler for error events
|
|
642
|
+
* @param handler Function to call when an error occurs
|
|
643
|
+
*/
|
|
644
|
+
onError(handler: ErrorHandler): void;
|
|
645
|
+
/**
|
|
646
|
+
* Check if the transport is currently connected
|
|
647
|
+
* @returns true if connected, false otherwise
|
|
648
|
+
*/
|
|
649
|
+
isConnected(): boolean;
|
|
650
|
+
/**
|
|
651
|
+
* Get the current connection state
|
|
652
|
+
* @returns The current ConnectionState
|
|
653
|
+
*/
|
|
654
|
+
getState(): ConnectionState;
|
|
655
|
+
}
|
|
656
|
+
|
|
519
657
|
/**
|
|
520
658
|
* Bridge Core - Main orchestration class for Claude Code Bridge
|
|
521
659
|
* Handles peer connections, message routing, and lifecycle management
|
|
@@ -525,8 +663,9 @@ declare function safeDeserializeMessage(json: string): z.SafeParseSuccess<{
|
|
|
525
663
|
* Bridge operation mode
|
|
526
664
|
* - 'host': Listen for incoming connections, sends commands via MCP
|
|
527
665
|
* - 'client': Connect to host, receives and executes commands
|
|
666
|
+
* - 'peer': Bidirectional mode - can both listen and connect
|
|
528
667
|
*/
|
|
529
|
-
type BridgeMode = 'host' | 'client';
|
|
668
|
+
type BridgeMode = 'host' | 'client' | 'peer';
|
|
530
669
|
/**
|
|
531
670
|
* Configuration for the bridge's listening server
|
|
532
671
|
*/
|
|
@@ -535,17 +674,25 @@ interface BridgeListenConfig {
|
|
|
535
674
|
port: number;
|
|
536
675
|
/** Host to bind to (default: 0.0.0.0) */
|
|
537
676
|
host?: string;
|
|
677
|
+
/** TLS configuration for secure connections */
|
|
678
|
+
tls?: TLSConfig$2;
|
|
679
|
+
/** Authentication configuration */
|
|
680
|
+
auth?: AuthConfig$2;
|
|
538
681
|
}
|
|
539
682
|
/**
|
|
540
683
|
* Configuration for connecting to a remote bridge
|
|
541
684
|
*/
|
|
542
685
|
interface BridgeConnectConfig {
|
|
543
|
-
/** Full WebSocket URL (e.g., ws://localhost:8765) */
|
|
686
|
+
/** Full WebSocket URL (e.g., ws://localhost:8765 or wss://localhost:8765) */
|
|
544
687
|
url?: string;
|
|
545
688
|
/** Use host.docker.internal for container-to-host connection */
|
|
546
689
|
hostGateway?: boolean;
|
|
547
690
|
/** Port to connect to (used if url is not provided) */
|
|
548
691
|
port?: number;
|
|
692
|
+
/** TLS configuration for secure connections */
|
|
693
|
+
tls?: TLSConfig$2;
|
|
694
|
+
/** Authentication configuration */
|
|
695
|
+
auth?: AuthConfig$2;
|
|
549
696
|
}
|
|
550
697
|
/**
|
|
551
698
|
* Context sharing configuration
|
|
@@ -623,9 +770,11 @@ type ContextRequestedHandler = (query: string, peerId: string) => FileChunk[] |
|
|
|
623
770
|
declare class Bridge {
|
|
624
771
|
private config;
|
|
625
772
|
private server;
|
|
773
|
+
private httpsServer;
|
|
626
774
|
private clientTransport;
|
|
627
775
|
private peers;
|
|
628
776
|
private started;
|
|
777
|
+
private authenticator;
|
|
629
778
|
private peerConnectedHandlers;
|
|
630
779
|
private peerDisconnectedHandlers;
|
|
631
780
|
private messageReceivedHandlers;
|
|
@@ -648,6 +797,7 @@ declare class Bridge {
|
|
|
648
797
|
* Start the bridge based on configured mode
|
|
649
798
|
* - 'host': Starts WebSocket server, sends commands via MCP
|
|
650
799
|
* - 'client': Connects to host, receives and executes commands
|
|
800
|
+
* - 'peer': Starts server (if listen configured) and connects to remote (if connect configured)
|
|
651
801
|
*/
|
|
652
802
|
start(): Promise<void>;
|
|
653
803
|
/**
|
|
@@ -744,8 +894,15 @@ declare class Bridge {
|
|
|
744
894
|
stopAutoSync(): void;
|
|
745
895
|
/**
|
|
746
896
|
* Start the WebSocket server
|
|
897
|
+
* If TLS is configured, starts an HTTPS server with WebSocket upgrade
|
|
898
|
+
* If auth is configured, validates connections before accepting
|
|
747
899
|
*/
|
|
748
900
|
private startServer;
|
|
901
|
+
/**
|
|
902
|
+
* Verify client connection for authentication
|
|
903
|
+
* Used as WebSocketServer verifyClient callback
|
|
904
|
+
*/
|
|
905
|
+
private verifyClient;
|
|
749
906
|
/**
|
|
750
907
|
* Handle a new incoming connection
|
|
751
908
|
*/
|
|
@@ -1053,115 +1210,6 @@ declare class ContextManager {
|
|
|
1053
1210
|
private truncateContent;
|
|
1054
1211
|
}
|
|
1055
1212
|
|
|
1056
|
-
/**
|
|
1057
|
-
* Transport layer interface and types for Claude Code Bridge
|
|
1058
|
-
* Defines the abstract transport interface for communication between bridge instances
|
|
1059
|
-
*/
|
|
1060
|
-
|
|
1061
|
-
/**
|
|
1062
|
-
* Represents the current state of a transport connection
|
|
1063
|
-
*/
|
|
1064
|
-
declare enum ConnectionState {
|
|
1065
|
-
/** Not connected to any peer */
|
|
1066
|
-
DISCONNECTED = "DISCONNECTED",
|
|
1067
|
-
/** Currently attempting to establish connection */
|
|
1068
|
-
CONNECTING = "CONNECTING",
|
|
1069
|
-
/** Successfully connected and ready for communication */
|
|
1070
|
-
CONNECTED = "CONNECTED",
|
|
1071
|
-
/** Connection lost, attempting to reconnect */
|
|
1072
|
-
RECONNECTING = "RECONNECTING"
|
|
1073
|
-
}
|
|
1074
|
-
/**
|
|
1075
|
-
* Authentication configuration for transport connections
|
|
1076
|
-
*/
|
|
1077
|
-
interface AuthConfig {
|
|
1078
|
-
/** Authentication type */
|
|
1079
|
-
type: 'token' | 'none';
|
|
1080
|
-
/** Authentication token (required if type is 'token') */
|
|
1081
|
-
token?: string;
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* Configuration for establishing a transport connection
|
|
1085
|
-
*/
|
|
1086
|
-
interface ConnectionConfig {
|
|
1087
|
-
/** Full WebSocket URL (e.g., ws://localhost:8765) */
|
|
1088
|
-
url?: string;
|
|
1089
|
-
/** Host to connect to (used if url is not provided) */
|
|
1090
|
-
host?: string;
|
|
1091
|
-
/** Port to connect to (used if url is not provided) */
|
|
1092
|
-
port?: number;
|
|
1093
|
-
/** Enable automatic reconnection on disconnect */
|
|
1094
|
-
reconnect?: boolean;
|
|
1095
|
-
/** Interval between reconnection attempts in milliseconds */
|
|
1096
|
-
reconnectInterval?: number;
|
|
1097
|
-
/** Maximum number of reconnection attempts before giving up */
|
|
1098
|
-
maxReconnectAttempts?: number;
|
|
1099
|
-
/** Authentication configuration */
|
|
1100
|
-
auth?: AuthConfig;
|
|
1101
|
-
}
|
|
1102
|
-
/**
|
|
1103
|
-
* Handler for incoming messages
|
|
1104
|
-
*/
|
|
1105
|
-
type MessageHandler = (message: BridgeMessage) => void;
|
|
1106
|
-
/**
|
|
1107
|
-
* Handler for disconnect events
|
|
1108
|
-
*/
|
|
1109
|
-
type DisconnectHandler = () => void;
|
|
1110
|
-
/**
|
|
1111
|
-
* Handler for error events
|
|
1112
|
-
*/
|
|
1113
|
-
type ErrorHandler = (error: Error) => void;
|
|
1114
|
-
/**
|
|
1115
|
-
* Abstract transport interface for bridge communication
|
|
1116
|
-
* Implementations handle the actual network protocol (WebSocket, TCP, etc.)
|
|
1117
|
-
*/
|
|
1118
|
-
interface Transport {
|
|
1119
|
-
/**
|
|
1120
|
-
* Establish connection to a remote peer
|
|
1121
|
-
* @param config Connection configuration
|
|
1122
|
-
* @returns Promise that resolves when connection is established
|
|
1123
|
-
* @throws Error if connection fails
|
|
1124
|
-
*/
|
|
1125
|
-
connect(config: ConnectionConfig): Promise<void>;
|
|
1126
|
-
/**
|
|
1127
|
-
* Cleanly close the current connection
|
|
1128
|
-
* @returns Promise that resolves when disconnection is complete
|
|
1129
|
-
*/
|
|
1130
|
-
disconnect(): Promise<void>;
|
|
1131
|
-
/**
|
|
1132
|
-
* Send a message to the connected peer
|
|
1133
|
-
* @param message The message to send
|
|
1134
|
-
* @returns Promise that resolves when message is sent
|
|
1135
|
-
* @throws Error if not connected and message cannot be queued
|
|
1136
|
-
*/
|
|
1137
|
-
send(message: BridgeMessage): Promise<void>;
|
|
1138
|
-
/**
|
|
1139
|
-
* Register a handler for incoming messages
|
|
1140
|
-
* @param handler Function to call when a message is received
|
|
1141
|
-
*/
|
|
1142
|
-
onMessage(handler: MessageHandler): void;
|
|
1143
|
-
/**
|
|
1144
|
-
* Register a handler for disconnect events
|
|
1145
|
-
* @param handler Function to call when connection is lost
|
|
1146
|
-
*/
|
|
1147
|
-
onDisconnect(handler: DisconnectHandler): void;
|
|
1148
|
-
/**
|
|
1149
|
-
* Register a handler for error events
|
|
1150
|
-
* @param handler Function to call when an error occurs
|
|
1151
|
-
*/
|
|
1152
|
-
onError(handler: ErrorHandler): void;
|
|
1153
|
-
/**
|
|
1154
|
-
* Check if the transport is currently connected
|
|
1155
|
-
* @returns true if connected, false otherwise
|
|
1156
|
-
*/
|
|
1157
|
-
isConnected(): boolean;
|
|
1158
|
-
/**
|
|
1159
|
-
* Get the current connection state
|
|
1160
|
-
* @returns The current ConnectionState
|
|
1161
|
-
*/
|
|
1162
|
-
getState(): ConnectionState;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
1213
|
/**
|
|
1166
1214
|
* WebSocket Transport implementation for Claude Code Bridge
|
|
1167
1215
|
* Provides WebSocket-based communication between bridge instances
|
|
@@ -1189,8 +1237,17 @@ declare class WebSocketTransport implements Transport {
|
|
|
1189
1237
|
private reconnectingHandlers;
|
|
1190
1238
|
/**
|
|
1191
1239
|
* Build the WebSocket URL from the connection configuration
|
|
1240
|
+
* Uses wss:// if TLS is configured, ws:// otherwise
|
|
1192
1241
|
*/
|
|
1193
1242
|
private buildUrl;
|
|
1243
|
+
/**
|
|
1244
|
+
* Build WebSocket options including TLS and auth configuration
|
|
1245
|
+
*/
|
|
1246
|
+
private buildWsOptions;
|
|
1247
|
+
/**
|
|
1248
|
+
* Build URL with auth query parameters (fallback for servers that don't support headers)
|
|
1249
|
+
*/
|
|
1250
|
+
private buildUrlWithAuth;
|
|
1194
1251
|
/**
|
|
1195
1252
|
* Establish connection to a remote peer
|
|
1196
1253
|
*/
|
|
@@ -1356,12 +1413,50 @@ declare function createLogger(name: string, level?: LogLevel): Logger;
|
|
|
1356
1413
|
*/
|
|
1357
1414
|
declare function createChildLogger(parent: Logger, bindings: Record<string, unknown>): Logger;
|
|
1358
1415
|
|
|
1416
|
+
/**
|
|
1417
|
+
* TLS configuration for secure connections
|
|
1418
|
+
*/
|
|
1419
|
+
interface TLSConfig$1 {
|
|
1420
|
+
/** Path to certificate PEM file */
|
|
1421
|
+
cert?: string;
|
|
1422
|
+
/** Path to private key PEM file */
|
|
1423
|
+
key?: string;
|
|
1424
|
+
/** Path to CA certificate PEM file */
|
|
1425
|
+
ca?: string;
|
|
1426
|
+
/** Whether to reject unauthorized certificates (default: true) */
|
|
1427
|
+
rejectUnauthorized?: boolean;
|
|
1428
|
+
/** Passphrase for encrypted private key */
|
|
1429
|
+
passphrase?: string;
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Authentication type
|
|
1433
|
+
*/
|
|
1434
|
+
type AuthType$1 = 'none' | 'token' | 'password' | 'ip' | 'combined';
|
|
1435
|
+
/**
|
|
1436
|
+
* Authentication configuration
|
|
1437
|
+
*/
|
|
1438
|
+
interface AuthConfig$1 {
|
|
1439
|
+
/** Authentication type */
|
|
1440
|
+
type: AuthType$1;
|
|
1441
|
+
/** Authentication token */
|
|
1442
|
+
token?: string;
|
|
1443
|
+
/** Authentication password */
|
|
1444
|
+
password?: string;
|
|
1445
|
+
/** Allowed IP addresses/ranges in CIDR notation */
|
|
1446
|
+
allowedIps?: string[];
|
|
1447
|
+
/** If true, ALL configured methods must pass; if false, ANY passing method is sufficient */
|
|
1448
|
+
requireAll?: boolean;
|
|
1449
|
+
}
|
|
1359
1450
|
/**
|
|
1360
1451
|
* Configuration for the bridge's listening socket
|
|
1361
1452
|
*/
|
|
1362
1453
|
interface ListenConfig {
|
|
1363
1454
|
port: number;
|
|
1364
1455
|
host: string;
|
|
1456
|
+
/** TLS configuration for secure connections */
|
|
1457
|
+
tls?: TLSConfig$1;
|
|
1458
|
+
/** Authentication configuration */
|
|
1459
|
+
auth?: AuthConfig$1;
|
|
1365
1460
|
}
|
|
1366
1461
|
/**
|
|
1367
1462
|
* Configuration for connecting to a remote bridge
|
|
@@ -1370,6 +1465,10 @@ interface ConnectConfig {
|
|
|
1370
1465
|
url?: string;
|
|
1371
1466
|
hostGateway?: boolean;
|
|
1372
1467
|
port?: number;
|
|
1468
|
+
/** TLS configuration for secure connections */
|
|
1469
|
+
tls?: TLSConfig$1;
|
|
1470
|
+
/** Authentication configuration */
|
|
1471
|
+
auth?: AuthConfig$1;
|
|
1373
1472
|
}
|
|
1374
1473
|
/**
|
|
1375
1474
|
* Configuration for context sharing behavior
|
|
@@ -1603,6 +1702,212 @@ declare function wrapError(error: unknown, context: string): BridgeError;
|
|
|
1603
1702
|
*/
|
|
1604
1703
|
declare function isErrorCode(error: unknown, code: ErrorCode): boolean;
|
|
1605
1704
|
|
|
1705
|
+
/**
|
|
1706
|
+
* TLS utilities for Claude Code Bridge
|
|
1707
|
+
* Handles loading and validating TLS certificates for secure WebSocket connections
|
|
1708
|
+
*/
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* TLS configuration for secure connections
|
|
1712
|
+
*/
|
|
1713
|
+
interface TLSConfig {
|
|
1714
|
+
/** Path to certificate PEM file */
|
|
1715
|
+
cert?: string;
|
|
1716
|
+
/** Path to private key PEM file */
|
|
1717
|
+
key?: string;
|
|
1718
|
+
/** Path to CA certificate PEM file (for verifying client certs or self-signed server certs) */
|
|
1719
|
+
ca?: string;
|
|
1720
|
+
/** Whether to reject unauthorized certificates (default: true) */
|
|
1721
|
+
rejectUnauthorized?: boolean;
|
|
1722
|
+
/** Passphrase for encrypted private key */
|
|
1723
|
+
passphrase?: string;
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Result of TLS configuration validation
|
|
1727
|
+
*/
|
|
1728
|
+
interface TLSValidationResult {
|
|
1729
|
+
/** Whether the configuration is valid */
|
|
1730
|
+
valid: boolean;
|
|
1731
|
+
/** List of validation errors */
|
|
1732
|
+
errors: string[];
|
|
1733
|
+
/** List of validation warnings */
|
|
1734
|
+
warnings: string[];
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Loaded TLS options ready for use with https/tls modules
|
|
1738
|
+
*/
|
|
1739
|
+
interface LoadedTLSOptions {
|
|
1740
|
+
/** Certificate content */
|
|
1741
|
+
cert?: string | Buffer;
|
|
1742
|
+
/** Private key content */
|
|
1743
|
+
key?: string | Buffer;
|
|
1744
|
+
/** CA certificate content */
|
|
1745
|
+
ca?: string | Buffer;
|
|
1746
|
+
/** Whether to reject unauthorized certificates */
|
|
1747
|
+
rejectUnauthorized?: boolean;
|
|
1748
|
+
/** Passphrase for encrypted private key */
|
|
1749
|
+
passphrase?: string;
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Load TLS certificates from file paths
|
|
1753
|
+
* @param config - TLS configuration with file paths
|
|
1754
|
+
* @returns TLS options ready for use with https/tls modules
|
|
1755
|
+
* @throws Error if required certificates cannot be loaded
|
|
1756
|
+
*/
|
|
1757
|
+
declare function loadCertificates(config: TLSConfig): Promise<LoadedTLSOptions>;
|
|
1758
|
+
/**
|
|
1759
|
+
* Synchronous version of loadCertificates
|
|
1760
|
+
* @param config - TLS configuration with file paths
|
|
1761
|
+
* @returns TLS options ready for use with https/tls modules
|
|
1762
|
+
* @throws Error if required certificates cannot be loaded
|
|
1763
|
+
*/
|
|
1764
|
+
declare function loadCertificatesSync(config: TLSConfig): LoadedTLSOptions;
|
|
1765
|
+
/**
|
|
1766
|
+
* Validate TLS configuration
|
|
1767
|
+
* @param config - TLS configuration to validate
|
|
1768
|
+
* @returns Validation result with errors and warnings
|
|
1769
|
+
*/
|
|
1770
|
+
declare function validateTLSConfig(config: TLSConfig): TLSValidationResult;
|
|
1771
|
+
/**
|
|
1772
|
+
* Check if TLS is enabled in the configuration
|
|
1773
|
+
* @param config - TLS configuration to check
|
|
1774
|
+
* @returns true if TLS should be enabled (cert and key both provided)
|
|
1775
|
+
*/
|
|
1776
|
+
declare function isTLSEnabled(config?: TLSConfig): boolean;
|
|
1777
|
+
/**
|
|
1778
|
+
* Create TLS secure context options for Node.js tls module
|
|
1779
|
+
* @param loaded - Loaded TLS options
|
|
1780
|
+
* @returns Options for tls.createSecureContext
|
|
1781
|
+
*/
|
|
1782
|
+
declare function createSecureContextOptions(loaded: LoadedTLSOptions): tls.SecureContextOptions;
|
|
1783
|
+
|
|
1784
|
+
/**
|
|
1785
|
+
* Authentication utilities for Claude Code Bridge
|
|
1786
|
+
* Handles token, password, and IP-based authentication for WebSocket connections
|
|
1787
|
+
*/
|
|
1788
|
+
|
|
1789
|
+
/**
|
|
1790
|
+
* Authentication type
|
|
1791
|
+
*/
|
|
1792
|
+
type AuthType = 'none' | 'token' | 'password' | 'ip' | 'combined';
|
|
1793
|
+
/**
|
|
1794
|
+
* Authentication configuration
|
|
1795
|
+
*/
|
|
1796
|
+
interface AuthConfig {
|
|
1797
|
+
/** Authentication type */
|
|
1798
|
+
type: AuthType;
|
|
1799
|
+
/** Authentication token (for type: 'token' or 'combined') */
|
|
1800
|
+
token?: string;
|
|
1801
|
+
/** Authentication password (for type: 'password' or 'combined') */
|
|
1802
|
+
password?: string;
|
|
1803
|
+
/** Allowed IP addresses/ranges in CIDR notation (for type: 'ip' or 'combined') */
|
|
1804
|
+
allowedIps?: string[];
|
|
1805
|
+
/** If true, ALL configured methods must pass; if false, ANY passing method is sufficient */
|
|
1806
|
+
requireAll?: boolean;
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Authentication result
|
|
1810
|
+
*/
|
|
1811
|
+
interface AuthResult {
|
|
1812
|
+
/** Whether authentication succeeded */
|
|
1813
|
+
success: boolean;
|
|
1814
|
+
/** Error message if authentication failed */
|
|
1815
|
+
error?: string;
|
|
1816
|
+
/** Which authentication method succeeded (if any) */
|
|
1817
|
+
method?: 'token' | 'password' | 'ip';
|
|
1818
|
+
/** Client IP address */
|
|
1819
|
+
clientIp?: string;
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Credentials extracted from a request
|
|
1823
|
+
*/
|
|
1824
|
+
interface ExtractedCredentials {
|
|
1825
|
+
/** Token from query string or Authorization header */
|
|
1826
|
+
token?: string;
|
|
1827
|
+
/** Password from query string or header */
|
|
1828
|
+
password?: string;
|
|
1829
|
+
/** Client IP address */
|
|
1830
|
+
clientIp: string;
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* Check if an IP address matches any of the allowed ranges
|
|
1834
|
+
* @param clientIp - The IP address to check
|
|
1835
|
+
* @param allowedCidrs - Array of CIDR ranges
|
|
1836
|
+
* @returns true if the IP matches any range
|
|
1837
|
+
*/
|
|
1838
|
+
declare function validateIp(clientIp: string, allowedCidrs: string[]): boolean;
|
|
1839
|
+
/**
|
|
1840
|
+
* Validate a token using timing-safe comparison
|
|
1841
|
+
* @param provided - The provided token
|
|
1842
|
+
* @param expected - The expected token
|
|
1843
|
+
* @returns true if tokens match
|
|
1844
|
+
*/
|
|
1845
|
+
declare function validateToken(provided: string | undefined, expected: string): boolean;
|
|
1846
|
+
/**
|
|
1847
|
+
* Validate a password using timing-safe comparison
|
|
1848
|
+
* @param provided - The provided password
|
|
1849
|
+
* @param expected - The expected password
|
|
1850
|
+
* @returns true if passwords match
|
|
1851
|
+
*/
|
|
1852
|
+
declare function validatePassword(provided: string | undefined, expected: string): boolean;
|
|
1853
|
+
/**
|
|
1854
|
+
* Extract credentials from an HTTP request
|
|
1855
|
+
* Looks for token/password in query parameters and Authorization header
|
|
1856
|
+
*/
|
|
1857
|
+
declare function extractCredentials(request: IncomingMessage): ExtractedCredentials;
|
|
1858
|
+
/**
|
|
1859
|
+
* Authenticator class for validating connection requests
|
|
1860
|
+
*/
|
|
1861
|
+
declare class Authenticator {
|
|
1862
|
+
private config;
|
|
1863
|
+
/**
|
|
1864
|
+
* Create a new Authenticator
|
|
1865
|
+
* @param config - Authentication configuration
|
|
1866
|
+
*/
|
|
1867
|
+
constructor(config: AuthConfig);
|
|
1868
|
+
/**
|
|
1869
|
+
* Authenticate a request
|
|
1870
|
+
* @param request - The incoming HTTP request (WebSocket upgrade request)
|
|
1871
|
+
* @returns Authentication result
|
|
1872
|
+
*/
|
|
1873
|
+
authenticate(request: IncomingMessage): AuthResult;
|
|
1874
|
+
/**
|
|
1875
|
+
* Authenticate with extracted credentials
|
|
1876
|
+
* @param credentials - The extracted credentials
|
|
1877
|
+
* @returns Authentication result
|
|
1878
|
+
*/
|
|
1879
|
+
authenticateWithCredentials(credentials: ExtractedCredentials): AuthResult;
|
|
1880
|
+
/**
|
|
1881
|
+
* Get the configured authentication type
|
|
1882
|
+
*/
|
|
1883
|
+
getType(): AuthType;
|
|
1884
|
+
/**
|
|
1885
|
+
* Check if authentication is required
|
|
1886
|
+
*/
|
|
1887
|
+
isRequired(): boolean;
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Create an AuthConfig from CLI options
|
|
1891
|
+
* @param options - CLI options object
|
|
1892
|
+
* @returns AuthConfig
|
|
1893
|
+
*/
|
|
1894
|
+
declare function createAuthConfigFromOptions(options: {
|
|
1895
|
+
authToken?: string;
|
|
1896
|
+
authPassword?: string;
|
|
1897
|
+
authIp?: string[];
|
|
1898
|
+
authRequireAll?: boolean;
|
|
1899
|
+
}): AuthConfig;
|
|
1900
|
+
/**
|
|
1901
|
+
* Validate an AuthConfig
|
|
1902
|
+
* @param config - AuthConfig to validate
|
|
1903
|
+
* @returns Validation result with errors and warnings
|
|
1904
|
+
*/
|
|
1905
|
+
declare function validateAuthConfig(config: AuthConfig): {
|
|
1906
|
+
valid: boolean;
|
|
1907
|
+
errors: string[];
|
|
1908
|
+
warnings: string[];
|
|
1909
|
+
};
|
|
1910
|
+
|
|
1606
1911
|
/**
|
|
1607
1912
|
* MCP Server for Claude Code Bridge
|
|
1608
1913
|
* Exposes bridge functionality as MCP tools for Claude Code integration
|
|
@@ -1619,6 +1924,10 @@ interface McpServerConfig {
|
|
|
1619
1924
|
instanceName?: string;
|
|
1620
1925
|
/** Task timeout in milliseconds */
|
|
1621
1926
|
taskTimeout?: number;
|
|
1927
|
+
/** TLS configuration for secure connections */
|
|
1928
|
+
tls?: TLSConfig$2;
|
|
1929
|
+
/** Authentication configuration */
|
|
1930
|
+
auth?: AuthConfig$2;
|
|
1622
1931
|
}
|
|
1623
1932
|
/**
|
|
1624
1933
|
* MCP Server that exposes bridge functionality as tools
|
|
@@ -1687,4 +1996,4 @@ declare function createToolHandlers(bridge: Bridge): Record<string, (args: Recor
|
|
|
1687
1996
|
*/
|
|
1688
1997
|
declare const VERSION = "0.1.0";
|
|
1689
1998
|
|
|
1690
|
-
export { type Artifact, ArtifactSchema, Bridge, type BridgeConfig$1 as BridgeConfig, type BridgeConnectConfig, BridgeError, BridgeLifecycleError, type BridgeListenConfig, BridgeMcpServer, type BridgeMessage, BridgeMessageSchema, type BridgeMode, type BuildDirectoryTreeOptions, ConfigurationError, type ConnectConfig, type ConnectionConfig, ConnectionError, ConnectionState, type Context, type ContextDelta, ContextError, ContextManager, type ContextManagerOptions, type ContextReceivedHandler, type ContextRequestedHandler, ContextSchema, type ContextSharingConfig$1 as ContextSharingConfig, DEFAULT_CONFIG, type DirectoryTree, DirectoryTreeSchema, type ErrorCode, ErrorCodes, type FileChange, type FileChunk, FileChunkSchema, type InteractionConfig, type ListenConfig, type LogLevel, type Logger, type McpServerConfig, type MessageReceivedHandler, MessageType, type NotificationData, type PeerConnectedHandler, type PeerDisconnectedHandler, PeerError, type PeerInfo, type ProjectSnapshot, ProtocolError, TOOL_DEFINITIONS, TaskError, type TaskReceivedHandler, type TaskRequest, TaskRequestSchema, type TaskResult, TaskResultSchema, type ToolDefinition, type ToolResponse, type Transport, type BridgeConfig as UtilsBridgeConfig, type ContextSharingConfig as UtilsContextSharingConfig, VERSION, WebSocketTransport, buildDirectoryTree, createChildLogger, createContextRequestMessage, createContextSyncMessage, createLogger, createMessage, createNotificationMessage, createTaskDelegateMessage, createTaskResponseMessage, createToolHandlers, createTransport, deserializeMessage, estimateTokens, formatErrorForLogging, isErrorCode, loadConfig, loadConfigSync, mergeConfig, safeDeserializeMessage, safeValidateMessage, serializeMessage, startMcpServer, truncateToTokenLimit, validateMessage, wrapError };
|
|
1999
|
+
export { type Artifact, ArtifactSchema, type AuthConfig, type AuthResult, type AuthType, Authenticator, Bridge, type BridgeConfig$1 as BridgeConfig, type BridgeConnectConfig, BridgeError, BridgeLifecycleError, type BridgeListenConfig, BridgeMcpServer, type BridgeMessage, BridgeMessageSchema, type BridgeMode, type BuildDirectoryTreeOptions, ConfigurationError, type ConnectConfig, type ConnectionConfig, ConnectionError, ConnectionState, type Context, type ContextDelta, ContextError, ContextManager, type ContextManagerOptions, type ContextReceivedHandler, type ContextRequestedHandler, ContextSchema, type ContextSharingConfig$1 as ContextSharingConfig, DEFAULT_CONFIG, type DirectoryTree, DirectoryTreeSchema, type ErrorCode, ErrorCodes, type ExtractedCredentials, type FileChange, type FileChunk, FileChunkSchema, type InteractionConfig, type ListenConfig, type LoadedTLSOptions, type LogLevel, type Logger, type McpServerConfig, type MessageReceivedHandler, MessageType, type NotificationData, type PeerConnectedHandler, type PeerDisconnectedHandler, PeerError, type PeerInfo, type ProjectSnapshot, ProtocolError, type TLSConfig, type TLSValidationResult, TOOL_DEFINITIONS, TaskError, type TaskReceivedHandler, type TaskRequest, TaskRequestSchema, type TaskResult, TaskResultSchema, type ToolDefinition, type ToolResponse, type Transport, type BridgeConfig as UtilsBridgeConfig, type ContextSharingConfig as UtilsContextSharingConfig, VERSION, WebSocketTransport, buildDirectoryTree, createAuthConfigFromOptions, createChildLogger, createContextRequestMessage, createContextSyncMessage, createLogger, createMessage, createNotificationMessage, createSecureContextOptions, createTaskDelegateMessage, createTaskResponseMessage, createToolHandlers, createTransport, deserializeMessage, estimateTokens, extractCredentials, formatErrorForLogging, isErrorCode, isTLSEnabled, loadCertificates, loadCertificatesSync, loadConfig, loadConfigSync, mergeConfig, safeDeserializeMessage, safeValidateMessage, serializeMessage, startMcpServer, truncateToTokenLimit, validateAuthConfig, validateIp, validateMessage, validatePassword, validateTLSConfig, validateToken, wrapError };
|