@elizaos/capacitor-gateway 1.0.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/ElizaosCapacitorGateway.podspec +17 -0
- package/android/build.gradle +49 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/ai/eliza/plugins/gateway/GatewayPlugin.kt +614 -0
- package/dist/esm/definitions.d.ts +271 -0
- package/dist/esm/definitions.js +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/web.d.ts +99 -0
- package/dist/esm/web.js +419 -0
- package/dist/plugin.cjs.js +435 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +438 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/GatewayPlugin/GatewayPlugin.swift +631 -0
- package/package.json +103 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from "@capacitor/core";
|
|
2
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
3
|
+
export interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
7
|
+
/**
|
|
8
|
+
* Discovered gateway endpoint
|
|
9
|
+
*/
|
|
10
|
+
export interface GatewayEndpoint {
|
|
11
|
+
/** Stable unique identifier for this gateway */
|
|
12
|
+
stableId: string;
|
|
13
|
+
/** Display name of the gateway */
|
|
14
|
+
name: string;
|
|
15
|
+
/** IP address or hostname */
|
|
16
|
+
host: string;
|
|
17
|
+
/** Port number */
|
|
18
|
+
port: number;
|
|
19
|
+
/** LAN-specific hostname (if available) */
|
|
20
|
+
lanHost?: string;
|
|
21
|
+
/** Tailscale DNS hostname (if available) */
|
|
22
|
+
tailnetDns?: string;
|
|
23
|
+
/** Gateway port (may differ from discovery port) */
|
|
24
|
+
gatewayPort?: number;
|
|
25
|
+
/** Canvas port */
|
|
26
|
+
canvasPort?: number;
|
|
27
|
+
/** Whether TLS is enabled */
|
|
28
|
+
tlsEnabled: boolean;
|
|
29
|
+
/** SHA256 fingerprint for TLS certificate pinning */
|
|
30
|
+
tlsFingerprintSha256?: string;
|
|
31
|
+
/** Whether this was discovered locally vs wide-area */
|
|
32
|
+
isLocal: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Discovery options
|
|
36
|
+
*/
|
|
37
|
+
export interface GatewayDiscoveryOptions {
|
|
38
|
+
/** Optional wide-area domain for DNS-SD discovery (e.g., tailnet domain) */
|
|
39
|
+
wideAreaDomain?: string;
|
|
40
|
+
/** Timeout for discovery in milliseconds (default: 10000) */
|
|
41
|
+
timeout?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Discovery result
|
|
45
|
+
*/
|
|
46
|
+
export interface GatewayDiscoveryResult {
|
|
47
|
+
/** List of discovered gateways */
|
|
48
|
+
gateways: GatewayEndpoint[];
|
|
49
|
+
/** Status message */
|
|
50
|
+
status: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gateway discovery event
|
|
54
|
+
*/
|
|
55
|
+
export interface GatewayDiscoveryEvent {
|
|
56
|
+
/** Type of discovery event */
|
|
57
|
+
type: "found" | "lost" | "updated";
|
|
58
|
+
/** The gateway that was found/lost/updated */
|
|
59
|
+
gateway: GatewayEndpoint;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Connection options for the Gateway
|
|
63
|
+
*/
|
|
64
|
+
export interface GatewayConnectOptions {
|
|
65
|
+
/** WebSocket URL of the gateway (e.g., wss://localhost:8080) */
|
|
66
|
+
url: string;
|
|
67
|
+
/** Optional authentication token */
|
|
68
|
+
token?: string;
|
|
69
|
+
/** Optional password for password-based auth */
|
|
70
|
+
password?: string;
|
|
71
|
+
/** Client name identifier (defaults to 'eliza-capacitor') */
|
|
72
|
+
clientName?: string;
|
|
73
|
+
/** Client version string */
|
|
74
|
+
clientVersion?: string;
|
|
75
|
+
/** Session key for chat sessions */
|
|
76
|
+
sessionKey?: string;
|
|
77
|
+
/** Role to request (defaults to 'operator') */
|
|
78
|
+
role?: string;
|
|
79
|
+
/** Scopes to request */
|
|
80
|
+
scopes?: string[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Result of a successful connection
|
|
84
|
+
*/
|
|
85
|
+
export interface GatewayConnectResult {
|
|
86
|
+
/** Whether the connection succeeded */
|
|
87
|
+
connected: boolean;
|
|
88
|
+
/** Session ID if connected */
|
|
89
|
+
sessionId?: string;
|
|
90
|
+
/** Protocol version negotiated */
|
|
91
|
+
protocol?: number;
|
|
92
|
+
/** Available gateway methods */
|
|
93
|
+
methods?: string[];
|
|
94
|
+
/** Available gateway events */
|
|
95
|
+
events?: string[];
|
|
96
|
+
/** Role assigned by the gateway */
|
|
97
|
+
role?: string;
|
|
98
|
+
/** Scopes granted by the gateway */
|
|
99
|
+
scopes?: string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Options for sending a request
|
|
103
|
+
*/
|
|
104
|
+
export interface GatewaySendOptions {
|
|
105
|
+
/** RPC method name (e.g., 'chat.send', 'agents.list') */
|
|
106
|
+
method: string;
|
|
107
|
+
/** Parameters to send with the request */
|
|
108
|
+
params?: JsonObject;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Result of a send operation
|
|
112
|
+
*/
|
|
113
|
+
export interface GatewaySendResult {
|
|
114
|
+
/** Whether the request succeeded */
|
|
115
|
+
ok: boolean;
|
|
116
|
+
/** Response payload if successful */
|
|
117
|
+
payload?: JsonValue;
|
|
118
|
+
/** Error information if failed */
|
|
119
|
+
error?: {
|
|
120
|
+
code: string;
|
|
121
|
+
message: string;
|
|
122
|
+
details?: JsonValue;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Gateway event received from the server
|
|
127
|
+
*/
|
|
128
|
+
export interface GatewayEvent {
|
|
129
|
+
/** Event name */
|
|
130
|
+
event: string;
|
|
131
|
+
/** Event payload */
|
|
132
|
+
payload?: JsonValue;
|
|
133
|
+
/** Sequence number for ordering */
|
|
134
|
+
seq?: number;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Gateway message event (for chat streaming)
|
|
138
|
+
*/
|
|
139
|
+
export interface GatewayMessageEvent {
|
|
140
|
+
/** The raw message data */
|
|
141
|
+
data: JsonValue;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Gateway connection state change event
|
|
145
|
+
*/
|
|
146
|
+
export interface GatewayStateEvent {
|
|
147
|
+
/** New connection state */
|
|
148
|
+
state: "connecting" | "connected" | "disconnected" | "reconnecting";
|
|
149
|
+
/** Reason for state change */
|
|
150
|
+
reason?: string;
|
|
151
|
+
/** Error code if applicable */
|
|
152
|
+
code?: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Gateway error event
|
|
156
|
+
*/
|
|
157
|
+
export interface GatewayErrorEvent {
|
|
158
|
+
/** Error message */
|
|
159
|
+
message: string;
|
|
160
|
+
/** Error code */
|
|
161
|
+
code?: string;
|
|
162
|
+
/** Whether connection will retry */
|
|
163
|
+
willRetry: boolean;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Gateway Plugin Interface
|
|
167
|
+
*
|
|
168
|
+
* Provides WebSocket connectivity to an Eliza Gateway server.
|
|
169
|
+
* Handles authentication, reconnection, and RPC-style request/response
|
|
170
|
+
* as well as event streaming. Also supports gateway discovery via
|
|
171
|
+
* Bonjour/mDNS and wide-area DNS-SD.
|
|
172
|
+
*/
|
|
173
|
+
export interface GatewayPlugin {
|
|
174
|
+
/**
|
|
175
|
+
* Start gateway discovery
|
|
176
|
+
*
|
|
177
|
+
* Discovers gateways on the local network via Bonjour/mDNS and optionally
|
|
178
|
+
* via wide-area DNS-SD. Results are streamed via the 'discovery' event.
|
|
179
|
+
*
|
|
180
|
+
* @param options - Discovery options
|
|
181
|
+
* @returns Promise resolving to initial discovery result
|
|
182
|
+
*/
|
|
183
|
+
startDiscovery(options?: GatewayDiscoveryOptions): Promise<GatewayDiscoveryResult>;
|
|
184
|
+
/**
|
|
185
|
+
* Stop gateway discovery
|
|
186
|
+
*
|
|
187
|
+
* @returns Promise that resolves when discovery is stopped
|
|
188
|
+
*/
|
|
189
|
+
stopDiscovery(): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Get the list of currently discovered gateways
|
|
192
|
+
*
|
|
193
|
+
* @returns Promise resolving to current gateway list
|
|
194
|
+
*/
|
|
195
|
+
getDiscoveredGateways(): Promise<GatewayDiscoveryResult>;
|
|
196
|
+
/**
|
|
197
|
+
* Connect to a Gateway server
|
|
198
|
+
*
|
|
199
|
+
* @param options - Connection options including URL and auth
|
|
200
|
+
* @returns Promise resolving to connection result
|
|
201
|
+
*/
|
|
202
|
+
connect(options: GatewayConnectOptions): Promise<GatewayConnectResult>;
|
|
203
|
+
/**
|
|
204
|
+
* Disconnect from the current Gateway
|
|
205
|
+
*
|
|
206
|
+
* @returns Promise that resolves when disconnected
|
|
207
|
+
*/
|
|
208
|
+
disconnect(): Promise<void>;
|
|
209
|
+
/**
|
|
210
|
+
* Check if currently connected to a Gateway
|
|
211
|
+
*
|
|
212
|
+
* @returns Promise resolving to connection status
|
|
213
|
+
*/
|
|
214
|
+
isConnected(): Promise<{
|
|
215
|
+
connected: boolean;
|
|
216
|
+
}>;
|
|
217
|
+
/**
|
|
218
|
+
* Send an RPC request to the Gateway
|
|
219
|
+
*
|
|
220
|
+
* @param options - Request method and parameters
|
|
221
|
+
* @returns Promise resolving to the response
|
|
222
|
+
*/
|
|
223
|
+
send(options: GatewaySendOptions): Promise<GatewaySendResult>;
|
|
224
|
+
/**
|
|
225
|
+
* Get the current connection info
|
|
226
|
+
*
|
|
227
|
+
* @returns Promise resolving to connection details
|
|
228
|
+
*/
|
|
229
|
+
getConnectionInfo(): Promise<{
|
|
230
|
+
url: string | null;
|
|
231
|
+
sessionId: string | null;
|
|
232
|
+
protocol: number | null;
|
|
233
|
+
role: string | null;
|
|
234
|
+
}>;
|
|
235
|
+
/**
|
|
236
|
+
* Add a listener for Gateway events
|
|
237
|
+
*
|
|
238
|
+
* @param eventName - Name of the event to listen for
|
|
239
|
+
* @param listenerFunc - Callback function for events
|
|
240
|
+
* @returns Handle to remove the listener
|
|
241
|
+
*/
|
|
242
|
+
addListener(eventName: "gatewayEvent", listenerFunc: (event: GatewayEvent) => void): Promise<PluginListenerHandle>;
|
|
243
|
+
/**
|
|
244
|
+
* Add a listener for connection state changes
|
|
245
|
+
*
|
|
246
|
+
* @param eventName - 'stateChange'
|
|
247
|
+
* @param listenerFunc - Callback function for state changes
|
|
248
|
+
* @returns Handle to remove the listener
|
|
249
|
+
*/
|
|
250
|
+
addListener(eventName: "stateChange", listenerFunc: (event: GatewayStateEvent) => void): Promise<PluginListenerHandle>;
|
|
251
|
+
/**
|
|
252
|
+
* Add a listener for errors
|
|
253
|
+
*
|
|
254
|
+
* @param eventName - 'error'
|
|
255
|
+
* @param listenerFunc - Callback function for errors
|
|
256
|
+
* @returns Handle to remove the listener
|
|
257
|
+
*/
|
|
258
|
+
addListener(eventName: "error", listenerFunc: (event: GatewayErrorEvent) => void): Promise<PluginListenerHandle>;
|
|
259
|
+
/**
|
|
260
|
+
* Add a listener for gateway discovery events
|
|
261
|
+
*
|
|
262
|
+
* @param eventName - 'discovery'
|
|
263
|
+
* @param listenerFunc - Callback function for discovery events
|
|
264
|
+
* @returns Handle to remove the listener
|
|
265
|
+
*/
|
|
266
|
+
addListener(eventName: "discovery", listenerFunc: (event: GatewayDiscoveryEvent) => void): Promise<PluginListenerHandle>;
|
|
267
|
+
/**
|
|
268
|
+
* Remove all listeners for this plugin
|
|
269
|
+
*/
|
|
270
|
+
removeAllListeners(): Promise<void>;
|
|
271
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
import type { GatewayConnectOptions, GatewayConnectResult, GatewayDiscoveryResult, GatewaySendOptions, GatewaySendResult } from "./definitions";
|
|
3
|
+
/**
|
|
4
|
+
* Web implementation of the Gateway Plugin
|
|
5
|
+
*
|
|
6
|
+
* Uses browser WebSocket API for connectivity.
|
|
7
|
+
* Note: Web platform cannot perform Bonjour/mDNS discovery.
|
|
8
|
+
*/
|
|
9
|
+
export declare class GatewayWeb extends WebPlugin {
|
|
10
|
+
private ws;
|
|
11
|
+
private pending;
|
|
12
|
+
private options;
|
|
13
|
+
private sessionId;
|
|
14
|
+
private protocol;
|
|
15
|
+
private role;
|
|
16
|
+
private scopes;
|
|
17
|
+
private methods;
|
|
18
|
+
private events;
|
|
19
|
+
private lastSeq;
|
|
20
|
+
private reconnectTimer;
|
|
21
|
+
private backoffMs;
|
|
22
|
+
private closed;
|
|
23
|
+
private connectResolve;
|
|
24
|
+
private connectReject;
|
|
25
|
+
/**
|
|
26
|
+
* Start gateway discovery (not supported on web)
|
|
27
|
+
*
|
|
28
|
+
* On web platforms, Bonjour/mDNS discovery is not available.
|
|
29
|
+
* Returns an empty list of gateways.
|
|
30
|
+
*/
|
|
31
|
+
startDiscovery(): Promise<GatewayDiscoveryResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Stop gateway discovery (no-op on web)
|
|
34
|
+
*/
|
|
35
|
+
stopDiscovery(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Get discovered gateways (always empty on web)
|
|
38
|
+
*/
|
|
39
|
+
getDiscoveredGateways(): Promise<GatewayDiscoveryResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Connect to a Gateway server
|
|
42
|
+
*/
|
|
43
|
+
connect(options: GatewayConnectOptions): Promise<GatewayConnectResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Establish WebSocket connection
|
|
46
|
+
*/
|
|
47
|
+
private establishConnection;
|
|
48
|
+
/**
|
|
49
|
+
* Send the connect frame to authenticate
|
|
50
|
+
*/
|
|
51
|
+
private sendConnectFrame;
|
|
52
|
+
/**
|
|
53
|
+
* Handle successful hello response
|
|
54
|
+
*/
|
|
55
|
+
private handleHelloOk;
|
|
56
|
+
/**
|
|
57
|
+
* Handle incoming WebSocket message
|
|
58
|
+
*/
|
|
59
|
+
private handleMessage;
|
|
60
|
+
/**
|
|
61
|
+
* Handle WebSocket close
|
|
62
|
+
*/
|
|
63
|
+
private handleClose;
|
|
64
|
+
/**
|
|
65
|
+
* Schedule a reconnection attempt
|
|
66
|
+
*/
|
|
67
|
+
private scheduleReconnect;
|
|
68
|
+
/**
|
|
69
|
+
* Notify state change listeners
|
|
70
|
+
*/
|
|
71
|
+
private notifyStateChange;
|
|
72
|
+
/**
|
|
73
|
+
* Get platform identifier
|
|
74
|
+
*/
|
|
75
|
+
private getPlatform;
|
|
76
|
+
/**
|
|
77
|
+
* Disconnect from the Gateway
|
|
78
|
+
*/
|
|
79
|
+
disconnect(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Check if connected
|
|
82
|
+
*/
|
|
83
|
+
isConnected(): Promise<{
|
|
84
|
+
connected: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Send an RPC request
|
|
88
|
+
*/
|
|
89
|
+
send(options: GatewaySendOptions): Promise<GatewaySendResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Get connection info
|
|
92
|
+
*/
|
|
93
|
+
getConnectionInfo(): Promise<{
|
|
94
|
+
url: string | null;
|
|
95
|
+
sessionId: string | null;
|
|
96
|
+
protocol: number | null;
|
|
97
|
+
role: string | null;
|
|
98
|
+
}>;
|
|
99
|
+
}
|