@liveport/agent-sdk 0.1.1 → 0.1.2
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/README.md +2 -2
- package/dist/index.d.mts +90 -10
- package/dist/index.d.ts +90 -10
- package/dist/index.js +278 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +267 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/examples/01-basic-usage.ts +0 -40
- package/examples/02-testing-integration.ts +0 -75
- package/examples/03-ai-agent-workflow.ts +0 -175
- package/examples/04-multiple-tunnels.ts +0 -84
- package/examples/05-error-handling.ts +0 -148
- package/examples/README.md +0 -172
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ new LivePortAgent(config: LivePortAgentConfig)
|
|
|
66
66
|
| Option | Type | Required | Default | Description |
|
|
67
67
|
|--------|------|----------|---------|-------------|
|
|
68
68
|
| `key` | string | ✅ | - | Bridge key for authentication |
|
|
69
|
-
| `apiUrl` | string | ❌ | `https://
|
|
69
|
+
| `apiUrl` | string | ❌ | `https://liveport.dev` | API base URL |
|
|
70
70
|
| `timeout` | number | ❌ | `30000` | Default timeout in milliseconds |
|
|
71
71
|
|
|
72
72
|
**Example:**
|
|
@@ -74,7 +74,7 @@ new LivePortAgent(config: LivePortAgentConfig)
|
|
|
74
74
|
```typescript
|
|
75
75
|
const agent = new LivePortAgent({
|
|
76
76
|
key: 'lpk_abc123...',
|
|
77
|
-
apiUrl: 'https://
|
|
77
|
+
apiUrl: 'https://liveport.dev',
|
|
78
78
|
timeout: 60000
|
|
79
79
|
});
|
|
80
80
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
export { Tunnel } from '@liveport/shared';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* LivePort Agent SDK
|
|
5
3
|
*
|
|
6
4
|
* TypeScript SDK for AI agents to wait for and access localhost tunnels.
|
|
7
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* Tunnel record as stored in the database.
|
|
8
|
+
*
|
|
9
|
+
* TODO: Remove this duplicate once @liveport/shared is published to npm
|
|
10
|
+
* and agent-sdk can depend on it directly. Until then, keep in sync with
|
|
11
|
+
* the Tunnel type in packages/shared/src/types/index.ts.
|
|
12
|
+
*/
|
|
13
|
+
interface Tunnel {
|
|
14
|
+
id: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
bridgeKeyId?: string;
|
|
17
|
+
subdomain: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
localPort: number;
|
|
20
|
+
publicUrl: string;
|
|
21
|
+
region: string;
|
|
22
|
+
connectedAt: Date;
|
|
23
|
+
disconnectedAt?: Date;
|
|
24
|
+
requestCount: number;
|
|
25
|
+
bytesTransferred: number;
|
|
26
|
+
}
|
|
8
27
|
interface LivePortAgentConfig {
|
|
9
28
|
/** Bridge key for authentication */
|
|
10
29
|
key: string;
|
|
11
|
-
/** API base URL (default: https://
|
|
30
|
+
/** API base URL (default: https://liveport.dev) */
|
|
12
31
|
apiUrl?: string;
|
|
32
|
+
/** Tunnel server URL for connect() (default: https://tunnel.liveport.online) */
|
|
33
|
+
tunnelUrl?: string;
|
|
13
34
|
/** Default timeout in milliseconds (default: 30000) */
|
|
14
35
|
timeout?: number;
|
|
15
36
|
}
|
|
@@ -19,6 +40,20 @@ interface WaitForTunnelOptions {
|
|
|
19
40
|
/** Poll interval in milliseconds (default: 1000) */
|
|
20
41
|
pollInterval?: number;
|
|
21
42
|
}
|
|
43
|
+
interface ConnectOptions {
|
|
44
|
+
/** Tunnel server URL (overrides tunnelUrl from config) */
|
|
45
|
+
serverUrl?: string;
|
|
46
|
+
/** Connection timeout in milliseconds (default: 30000) */
|
|
47
|
+
timeout?: number;
|
|
48
|
+
}
|
|
49
|
+
interface WaitForReadyOptions {
|
|
50
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
51
|
+
timeout?: number;
|
|
52
|
+
/** Poll interval in milliseconds (default: 1000) */
|
|
53
|
+
pollInterval?: number;
|
|
54
|
+
/** Health check path (default: "/") */
|
|
55
|
+
healthPath?: string;
|
|
56
|
+
}
|
|
22
57
|
interface AgentTunnel {
|
|
23
58
|
tunnelId: string;
|
|
24
59
|
subdomain: string;
|
|
@@ -37,10 +72,14 @@ declare class ApiError extends Error {
|
|
|
37
72
|
readonly code: string;
|
|
38
73
|
constructor(statusCode: number, code: string, message: string);
|
|
39
74
|
}
|
|
75
|
+
/** Error thrown when WebSocket connection fails */
|
|
76
|
+
declare class ConnectionError extends Error {
|
|
77
|
+
constructor(message: string);
|
|
78
|
+
}
|
|
40
79
|
/**
|
|
41
80
|
* LivePort Agent SDK
|
|
42
81
|
*
|
|
43
|
-
* Allows AI agents to wait for and access localhost tunnels.
|
|
82
|
+
* Allows AI agents to wait for, connect to, and access localhost tunnels.
|
|
44
83
|
*
|
|
45
84
|
* @example
|
|
46
85
|
* ```typescript
|
|
@@ -50,9 +89,12 @@ declare class ApiError extends Error {
|
|
|
50
89
|
* key: process.env.LIVEPORT_BRIDGE_KEY!
|
|
51
90
|
* });
|
|
52
91
|
*
|
|
53
|
-
* //
|
|
54
|
-
* const tunnel = await agent.
|
|
55
|
-
* console.log(`
|
|
92
|
+
* // Create a tunnel to local port 3000
|
|
93
|
+
* const tunnel = await agent.connect(3000);
|
|
94
|
+
* console.log(`Tunnel URL: ${tunnel.url}`);
|
|
95
|
+
*
|
|
96
|
+
* // Wait for the local server to be reachable through the tunnel
|
|
97
|
+
* await agent.waitForReady(tunnel);
|
|
56
98
|
*
|
|
57
99
|
* // Run your tests against tunnel.url
|
|
58
100
|
*
|
|
@@ -63,8 +105,33 @@ declare class ApiError extends Error {
|
|
|
63
105
|
declare class LivePortAgent {
|
|
64
106
|
private config;
|
|
65
107
|
private abortController;
|
|
66
|
-
private
|
|
108
|
+
private wsConnection;
|
|
67
109
|
constructor(config: LivePortAgentConfig);
|
|
110
|
+
/**
|
|
111
|
+
* Connect to the tunnel server and create a tunnel for the given local port.
|
|
112
|
+
*
|
|
113
|
+
* Opens a WebSocket to the tunnel server, authenticates with the bridge key,
|
|
114
|
+
* and waits for a tunnel assignment. Incoming HTTP requests from the tunnel
|
|
115
|
+
* are forwarded to localhost:<port>.
|
|
116
|
+
*
|
|
117
|
+
* @param port - The local port to tunnel
|
|
118
|
+
* @param options - Connection options
|
|
119
|
+
* @returns The tunnel info once connected
|
|
120
|
+
* @throws ConnectionError if the connection fails or times out
|
|
121
|
+
*/
|
|
122
|
+
connect(port: number, options?: ConnectOptions): Promise<AgentTunnel>;
|
|
123
|
+
/**
|
|
124
|
+
* Wait for the tunnel's public URL to become reachable.
|
|
125
|
+
*
|
|
126
|
+
* Polls the tunnel's public URL (not localhost) with HTTP GET requests
|
|
127
|
+
* until a 2xx response is received, or the timeout is exceeded. This
|
|
128
|
+
* validates the full tunnel path end-to-end.
|
|
129
|
+
*
|
|
130
|
+
* @param tunnel - The tunnel to check
|
|
131
|
+
* @param options - Wait options
|
|
132
|
+
* @throws TunnelTimeoutError if the tunnel is not ready within timeout
|
|
133
|
+
*/
|
|
134
|
+
waitForReady(tunnel: AgentTunnel, options?: WaitForReadyOptions): Promise<void>;
|
|
68
135
|
/**
|
|
69
136
|
* Wait for a tunnel to become available
|
|
70
137
|
*
|
|
@@ -86,9 +153,22 @@ declare class LivePortAgent {
|
|
|
86
153
|
/**
|
|
87
154
|
* Disconnect and clean up
|
|
88
155
|
*
|
|
89
|
-
* Cancels any pending waitForTunnel calls
|
|
156
|
+
* Cancels any pending waitForTunnel calls and closes any WebSocket
|
|
157
|
+
* connection created by connect().
|
|
90
158
|
*/
|
|
91
159
|
disconnect(): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Build WebSocket URL from server URL
|
|
162
|
+
*/
|
|
163
|
+
private buildWebSocketUrl;
|
|
164
|
+
/**
|
|
165
|
+
* Handle incoming WebSocket messages from the tunnel server
|
|
166
|
+
*/
|
|
167
|
+
private handleWsMessage;
|
|
168
|
+
/**
|
|
169
|
+
* Forward an HTTP request from the tunnel server to localhost
|
|
170
|
+
*/
|
|
171
|
+
private handleHttpRequest;
|
|
92
172
|
/**
|
|
93
173
|
* Make an authenticated API request
|
|
94
174
|
*/
|
|
@@ -103,4 +183,4 @@ declare class LivePortAgent {
|
|
|
103
183
|
private sleep;
|
|
104
184
|
}
|
|
105
185
|
|
|
106
|
-
export { type AgentTunnel, ApiError, LivePortAgent, type LivePortAgentConfig, TunnelTimeoutError, type WaitForTunnelOptions };
|
|
186
|
+
export { type AgentTunnel, ApiError, type ConnectOptions, ConnectionError, LivePortAgent, type LivePortAgentConfig, type Tunnel, TunnelTimeoutError, type WaitForReadyOptions, type WaitForTunnelOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
export { Tunnel } from '@liveport/shared';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* LivePort Agent SDK
|
|
5
3
|
*
|
|
6
4
|
* TypeScript SDK for AI agents to wait for and access localhost tunnels.
|
|
7
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* Tunnel record as stored in the database.
|
|
8
|
+
*
|
|
9
|
+
* TODO: Remove this duplicate once @liveport/shared is published to npm
|
|
10
|
+
* and agent-sdk can depend on it directly. Until then, keep in sync with
|
|
11
|
+
* the Tunnel type in packages/shared/src/types/index.ts.
|
|
12
|
+
*/
|
|
13
|
+
interface Tunnel {
|
|
14
|
+
id: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
bridgeKeyId?: string;
|
|
17
|
+
subdomain: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
localPort: number;
|
|
20
|
+
publicUrl: string;
|
|
21
|
+
region: string;
|
|
22
|
+
connectedAt: Date;
|
|
23
|
+
disconnectedAt?: Date;
|
|
24
|
+
requestCount: number;
|
|
25
|
+
bytesTransferred: number;
|
|
26
|
+
}
|
|
8
27
|
interface LivePortAgentConfig {
|
|
9
28
|
/** Bridge key for authentication */
|
|
10
29
|
key: string;
|
|
11
|
-
/** API base URL (default: https://
|
|
30
|
+
/** API base URL (default: https://liveport.dev) */
|
|
12
31
|
apiUrl?: string;
|
|
32
|
+
/** Tunnel server URL for connect() (default: https://tunnel.liveport.online) */
|
|
33
|
+
tunnelUrl?: string;
|
|
13
34
|
/** Default timeout in milliseconds (default: 30000) */
|
|
14
35
|
timeout?: number;
|
|
15
36
|
}
|
|
@@ -19,6 +40,20 @@ interface WaitForTunnelOptions {
|
|
|
19
40
|
/** Poll interval in milliseconds (default: 1000) */
|
|
20
41
|
pollInterval?: number;
|
|
21
42
|
}
|
|
43
|
+
interface ConnectOptions {
|
|
44
|
+
/** Tunnel server URL (overrides tunnelUrl from config) */
|
|
45
|
+
serverUrl?: string;
|
|
46
|
+
/** Connection timeout in milliseconds (default: 30000) */
|
|
47
|
+
timeout?: number;
|
|
48
|
+
}
|
|
49
|
+
interface WaitForReadyOptions {
|
|
50
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
51
|
+
timeout?: number;
|
|
52
|
+
/** Poll interval in milliseconds (default: 1000) */
|
|
53
|
+
pollInterval?: number;
|
|
54
|
+
/** Health check path (default: "/") */
|
|
55
|
+
healthPath?: string;
|
|
56
|
+
}
|
|
22
57
|
interface AgentTunnel {
|
|
23
58
|
tunnelId: string;
|
|
24
59
|
subdomain: string;
|
|
@@ -37,10 +72,14 @@ declare class ApiError extends Error {
|
|
|
37
72
|
readonly code: string;
|
|
38
73
|
constructor(statusCode: number, code: string, message: string);
|
|
39
74
|
}
|
|
75
|
+
/** Error thrown when WebSocket connection fails */
|
|
76
|
+
declare class ConnectionError extends Error {
|
|
77
|
+
constructor(message: string);
|
|
78
|
+
}
|
|
40
79
|
/**
|
|
41
80
|
* LivePort Agent SDK
|
|
42
81
|
*
|
|
43
|
-
* Allows AI agents to wait for and access localhost tunnels.
|
|
82
|
+
* Allows AI agents to wait for, connect to, and access localhost tunnels.
|
|
44
83
|
*
|
|
45
84
|
* @example
|
|
46
85
|
* ```typescript
|
|
@@ -50,9 +89,12 @@ declare class ApiError extends Error {
|
|
|
50
89
|
* key: process.env.LIVEPORT_BRIDGE_KEY!
|
|
51
90
|
* });
|
|
52
91
|
*
|
|
53
|
-
* //
|
|
54
|
-
* const tunnel = await agent.
|
|
55
|
-
* console.log(`
|
|
92
|
+
* // Create a tunnel to local port 3000
|
|
93
|
+
* const tunnel = await agent.connect(3000);
|
|
94
|
+
* console.log(`Tunnel URL: ${tunnel.url}`);
|
|
95
|
+
*
|
|
96
|
+
* // Wait for the local server to be reachable through the tunnel
|
|
97
|
+
* await agent.waitForReady(tunnel);
|
|
56
98
|
*
|
|
57
99
|
* // Run your tests against tunnel.url
|
|
58
100
|
*
|
|
@@ -63,8 +105,33 @@ declare class ApiError extends Error {
|
|
|
63
105
|
declare class LivePortAgent {
|
|
64
106
|
private config;
|
|
65
107
|
private abortController;
|
|
66
|
-
private
|
|
108
|
+
private wsConnection;
|
|
67
109
|
constructor(config: LivePortAgentConfig);
|
|
110
|
+
/**
|
|
111
|
+
* Connect to the tunnel server and create a tunnel for the given local port.
|
|
112
|
+
*
|
|
113
|
+
* Opens a WebSocket to the tunnel server, authenticates with the bridge key,
|
|
114
|
+
* and waits for a tunnel assignment. Incoming HTTP requests from the tunnel
|
|
115
|
+
* are forwarded to localhost:<port>.
|
|
116
|
+
*
|
|
117
|
+
* @param port - The local port to tunnel
|
|
118
|
+
* @param options - Connection options
|
|
119
|
+
* @returns The tunnel info once connected
|
|
120
|
+
* @throws ConnectionError if the connection fails or times out
|
|
121
|
+
*/
|
|
122
|
+
connect(port: number, options?: ConnectOptions): Promise<AgentTunnel>;
|
|
123
|
+
/**
|
|
124
|
+
* Wait for the tunnel's public URL to become reachable.
|
|
125
|
+
*
|
|
126
|
+
* Polls the tunnel's public URL (not localhost) with HTTP GET requests
|
|
127
|
+
* until a 2xx response is received, or the timeout is exceeded. This
|
|
128
|
+
* validates the full tunnel path end-to-end.
|
|
129
|
+
*
|
|
130
|
+
* @param tunnel - The tunnel to check
|
|
131
|
+
* @param options - Wait options
|
|
132
|
+
* @throws TunnelTimeoutError if the tunnel is not ready within timeout
|
|
133
|
+
*/
|
|
134
|
+
waitForReady(tunnel: AgentTunnel, options?: WaitForReadyOptions): Promise<void>;
|
|
68
135
|
/**
|
|
69
136
|
* Wait for a tunnel to become available
|
|
70
137
|
*
|
|
@@ -86,9 +153,22 @@ declare class LivePortAgent {
|
|
|
86
153
|
/**
|
|
87
154
|
* Disconnect and clean up
|
|
88
155
|
*
|
|
89
|
-
* Cancels any pending waitForTunnel calls
|
|
156
|
+
* Cancels any pending waitForTunnel calls and closes any WebSocket
|
|
157
|
+
* connection created by connect().
|
|
90
158
|
*/
|
|
91
159
|
disconnect(): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Build WebSocket URL from server URL
|
|
162
|
+
*/
|
|
163
|
+
private buildWebSocketUrl;
|
|
164
|
+
/**
|
|
165
|
+
* Handle incoming WebSocket messages from the tunnel server
|
|
166
|
+
*/
|
|
167
|
+
private handleWsMessage;
|
|
168
|
+
/**
|
|
169
|
+
* Forward an HTTP request from the tunnel server to localhost
|
|
170
|
+
*/
|
|
171
|
+
private handleHttpRequest;
|
|
92
172
|
/**
|
|
93
173
|
* Make an authenticated API request
|
|
94
174
|
*/
|
|
@@ -103,4 +183,4 @@ declare class LivePortAgent {
|
|
|
103
183
|
private sleep;
|
|
104
184
|
}
|
|
105
185
|
|
|
106
|
-
export { type AgentTunnel, ApiError, LivePortAgent, type LivePortAgentConfig, TunnelTimeoutError, type WaitForTunnelOptions };
|
|
186
|
+
export { type AgentTunnel, ApiError, type ConnectOptions, ConnectionError, LivePortAgent, type LivePortAgentConfig, type Tunnel, TunnelTimeoutError, type WaitForReadyOptions, type WaitForTunnelOptions };
|