@realtimex/sdk 1.0.5 → 1.0.6
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 +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +79 -0
- package/dist/index.mjs +68 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,7 @@ interface SDKConfig {
|
|
|
7
7
|
appId?: string;
|
|
8
8
|
appName?: string;
|
|
9
9
|
};
|
|
10
|
+
defaultPort?: number;
|
|
10
11
|
}
|
|
11
12
|
interface Activity {
|
|
12
13
|
id: string;
|
|
@@ -173,6 +174,45 @@ declare class TaskModule {
|
|
|
173
174
|
private _sendEvent;
|
|
174
175
|
}
|
|
175
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Port utilities for Local Apps
|
|
179
|
+
* Helps find available ports to avoid conflicts when multiple apps run simultaneously
|
|
180
|
+
*/
|
|
181
|
+
declare class PortModule {
|
|
182
|
+
private defaultPort;
|
|
183
|
+
constructor(defaultPort?: number);
|
|
184
|
+
/**
|
|
185
|
+
* Get suggested port from environment (RTX_PORT) or default
|
|
186
|
+
*/
|
|
187
|
+
getSuggestedPort(): number;
|
|
188
|
+
/**
|
|
189
|
+
* Check if a port is available
|
|
190
|
+
* @param port - Port number to check
|
|
191
|
+
* @returns Promise resolving to true if port is available
|
|
192
|
+
*/
|
|
193
|
+
isPortAvailable(port: number): Promise<boolean>;
|
|
194
|
+
/**
|
|
195
|
+
* Find an available port starting from the suggested port
|
|
196
|
+
* @param startPort - Starting port number (default: RTX_PORT or defaultPort)
|
|
197
|
+
* @param maxAttempts - Maximum ports to try (default: 100)
|
|
198
|
+
* @returns Promise resolving to an available port number
|
|
199
|
+
* @throws Error if no available port found in range
|
|
200
|
+
*/
|
|
201
|
+
findAvailablePort(startPort?: number, maxAttempts?: number): Promise<number>;
|
|
202
|
+
/**
|
|
203
|
+
* Get a ready-to-use port
|
|
204
|
+
* Returns the suggested port if available, otherwise finds the next available port
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const sdk = new RealtimeXSDK();
|
|
209
|
+
* const port = await sdk.port.getPort();
|
|
210
|
+
* app.listen(port);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
getPort(): Promise<number>;
|
|
214
|
+
}
|
|
215
|
+
|
|
176
216
|
/**
|
|
177
217
|
* RealtimeX Local App SDK
|
|
178
218
|
*
|
|
@@ -185,6 +225,7 @@ declare class RealtimeXSDK {
|
|
|
185
225
|
webhook: WebhookModule;
|
|
186
226
|
api: ApiModule;
|
|
187
227
|
task: TaskModule;
|
|
228
|
+
port: PortModule;
|
|
188
229
|
readonly appId: string;
|
|
189
230
|
readonly appName: string | undefined;
|
|
190
231
|
private static DEFAULT_REALTIMEX_URL;
|
|
@@ -195,4 +236,4 @@ declare class RealtimeXSDK {
|
|
|
195
236
|
private getEnvVar;
|
|
196
237
|
}
|
|
197
238
|
|
|
198
|
-
export { ActivitiesModule, type Activity, type Agent, ApiModule, RealtimeXSDK, type SDKConfig, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, WebhookModule, type Workspace };
|
|
239
|
+
export { ActivitiesModule, type Activity, type Agent, ApiModule, PortModule, RealtimeXSDK, type SDKConfig, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, WebhookModule, type Workspace };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ interface SDKConfig {
|
|
|
7
7
|
appId?: string;
|
|
8
8
|
appName?: string;
|
|
9
9
|
};
|
|
10
|
+
defaultPort?: number;
|
|
10
11
|
}
|
|
11
12
|
interface Activity {
|
|
12
13
|
id: string;
|
|
@@ -173,6 +174,45 @@ declare class TaskModule {
|
|
|
173
174
|
private _sendEvent;
|
|
174
175
|
}
|
|
175
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Port utilities for Local Apps
|
|
179
|
+
* Helps find available ports to avoid conflicts when multiple apps run simultaneously
|
|
180
|
+
*/
|
|
181
|
+
declare class PortModule {
|
|
182
|
+
private defaultPort;
|
|
183
|
+
constructor(defaultPort?: number);
|
|
184
|
+
/**
|
|
185
|
+
* Get suggested port from environment (RTX_PORT) or default
|
|
186
|
+
*/
|
|
187
|
+
getSuggestedPort(): number;
|
|
188
|
+
/**
|
|
189
|
+
* Check if a port is available
|
|
190
|
+
* @param port - Port number to check
|
|
191
|
+
* @returns Promise resolving to true if port is available
|
|
192
|
+
*/
|
|
193
|
+
isPortAvailable(port: number): Promise<boolean>;
|
|
194
|
+
/**
|
|
195
|
+
* Find an available port starting from the suggested port
|
|
196
|
+
* @param startPort - Starting port number (default: RTX_PORT or defaultPort)
|
|
197
|
+
* @param maxAttempts - Maximum ports to try (default: 100)
|
|
198
|
+
* @returns Promise resolving to an available port number
|
|
199
|
+
* @throws Error if no available port found in range
|
|
200
|
+
*/
|
|
201
|
+
findAvailablePort(startPort?: number, maxAttempts?: number): Promise<number>;
|
|
202
|
+
/**
|
|
203
|
+
* Get a ready-to-use port
|
|
204
|
+
* Returns the suggested port if available, otherwise finds the next available port
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const sdk = new RealtimeXSDK();
|
|
209
|
+
* const port = await sdk.port.getPort();
|
|
210
|
+
* app.listen(port);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
getPort(): Promise<number>;
|
|
214
|
+
}
|
|
215
|
+
|
|
176
216
|
/**
|
|
177
217
|
* RealtimeX Local App SDK
|
|
178
218
|
*
|
|
@@ -185,6 +225,7 @@ declare class RealtimeXSDK {
|
|
|
185
225
|
webhook: WebhookModule;
|
|
186
226
|
api: ApiModule;
|
|
187
227
|
task: TaskModule;
|
|
228
|
+
port: PortModule;
|
|
188
229
|
readonly appId: string;
|
|
189
230
|
readonly appName: string | undefined;
|
|
190
231
|
private static DEFAULT_REALTIMEX_URL;
|
|
@@ -195,4 +236,4 @@ declare class RealtimeXSDK {
|
|
|
195
236
|
private getEnvVar;
|
|
196
237
|
}
|
|
197
238
|
|
|
198
|
-
export { ActivitiesModule, type Activity, type Agent, ApiModule, RealtimeXSDK, type SDKConfig, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, WebhookModule, type Workspace };
|
|
239
|
+
export { ActivitiesModule, type Activity, type Agent, ApiModule, PortModule, RealtimeXSDK, type SDKConfig, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, WebhookModule, type Workspace };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -22,6 +32,7 @@ var index_exports = {};
|
|
|
22
32
|
__export(index_exports, {
|
|
23
33
|
ActivitiesModule: () => ActivitiesModule,
|
|
24
34
|
ApiModule: () => ApiModule,
|
|
35
|
+
PortModule: () => PortModule,
|
|
25
36
|
RealtimeXSDK: () => RealtimeXSDK,
|
|
26
37
|
TaskModule: () => TaskModule,
|
|
27
38
|
WebhookModule: () => WebhookModule
|
|
@@ -233,6 +244,72 @@ var TaskModule = class {
|
|
|
233
244
|
}
|
|
234
245
|
};
|
|
235
246
|
|
|
247
|
+
// src/modules/port.ts
|
|
248
|
+
var net = __toESM(require("net"));
|
|
249
|
+
var PortModule = class {
|
|
250
|
+
constructor(defaultPort = 8080) {
|
|
251
|
+
this.defaultPort = defaultPort;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get suggested port from environment (RTX_PORT) or default
|
|
255
|
+
*/
|
|
256
|
+
getSuggestedPort() {
|
|
257
|
+
const envPort = process.env.RTX_PORT;
|
|
258
|
+
return envPort ? parseInt(envPort, 10) : this.defaultPort;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Check if a port is available
|
|
262
|
+
* @param port - Port number to check
|
|
263
|
+
* @returns Promise resolving to true if port is available
|
|
264
|
+
*/
|
|
265
|
+
async isPortAvailable(port) {
|
|
266
|
+
return new Promise((resolve) => {
|
|
267
|
+
const server = net.createServer();
|
|
268
|
+
server.once("error", () => resolve(false));
|
|
269
|
+
server.once("listening", () => {
|
|
270
|
+
server.close();
|
|
271
|
+
resolve(true);
|
|
272
|
+
});
|
|
273
|
+
server.listen(port, "127.0.0.1");
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Find an available port starting from the suggested port
|
|
278
|
+
* @param startPort - Starting port number (default: RTX_PORT or defaultPort)
|
|
279
|
+
* @param maxAttempts - Maximum ports to try (default: 100)
|
|
280
|
+
* @returns Promise resolving to an available port number
|
|
281
|
+
* @throws Error if no available port found in range
|
|
282
|
+
*/
|
|
283
|
+
async findAvailablePort(startPort, maxAttempts = 100) {
|
|
284
|
+
const port = startPort ?? this.getSuggestedPort();
|
|
285
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
286
|
+
const currentPort = port + i;
|
|
287
|
+
if (await this.isPortAvailable(currentPort)) {
|
|
288
|
+
return currentPort;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
throw new Error(`No available port found in range ${port}-${port + maxAttempts - 1}`);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get a ready-to-use port
|
|
295
|
+
* Returns the suggested port if available, otherwise finds the next available port
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```typescript
|
|
299
|
+
* const sdk = new RealtimeXSDK();
|
|
300
|
+
* const port = await sdk.port.getPort();
|
|
301
|
+
* app.listen(port);
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
async getPort() {
|
|
305
|
+
const suggested = this.getSuggestedPort();
|
|
306
|
+
if (await this.isPortAvailable(suggested)) {
|
|
307
|
+
return suggested;
|
|
308
|
+
}
|
|
309
|
+
return this.findAvailablePort(suggested + 1);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
236
313
|
// src/index.ts
|
|
237
314
|
var _RealtimeXSDK = class _RealtimeXSDK {
|
|
238
315
|
constructor(config = {}) {
|
|
@@ -245,6 +322,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
245
322
|
this.webhook = new WebhookModule(realtimexUrl, this.appName, this.appId);
|
|
246
323
|
this.api = new ApiModule(realtimexUrl);
|
|
247
324
|
this.task = new TaskModule(realtimexUrl, this.appName, this.appId);
|
|
325
|
+
this.port = new PortModule(config.defaultPort);
|
|
248
326
|
}
|
|
249
327
|
/**
|
|
250
328
|
* Get environment variable (works in Node.js and browser)
|
|
@@ -265,6 +343,7 @@ var RealtimeXSDK = _RealtimeXSDK;
|
|
|
265
343
|
0 && (module.exports = {
|
|
266
344
|
ActivitiesModule,
|
|
267
345
|
ApiModule,
|
|
346
|
+
PortModule,
|
|
268
347
|
RealtimeXSDK,
|
|
269
348
|
TaskModule,
|
|
270
349
|
WebhookModule
|
package/dist/index.mjs
CHANGED
|
@@ -203,6 +203,72 @@ var TaskModule = class {
|
|
|
203
203
|
}
|
|
204
204
|
};
|
|
205
205
|
|
|
206
|
+
// src/modules/port.ts
|
|
207
|
+
import * as net from "net";
|
|
208
|
+
var PortModule = class {
|
|
209
|
+
constructor(defaultPort = 8080) {
|
|
210
|
+
this.defaultPort = defaultPort;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get suggested port from environment (RTX_PORT) or default
|
|
214
|
+
*/
|
|
215
|
+
getSuggestedPort() {
|
|
216
|
+
const envPort = process.env.RTX_PORT;
|
|
217
|
+
return envPort ? parseInt(envPort, 10) : this.defaultPort;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Check if a port is available
|
|
221
|
+
* @param port - Port number to check
|
|
222
|
+
* @returns Promise resolving to true if port is available
|
|
223
|
+
*/
|
|
224
|
+
async isPortAvailable(port) {
|
|
225
|
+
return new Promise((resolve) => {
|
|
226
|
+
const server = net.createServer();
|
|
227
|
+
server.once("error", () => resolve(false));
|
|
228
|
+
server.once("listening", () => {
|
|
229
|
+
server.close();
|
|
230
|
+
resolve(true);
|
|
231
|
+
});
|
|
232
|
+
server.listen(port, "127.0.0.1");
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Find an available port starting from the suggested port
|
|
237
|
+
* @param startPort - Starting port number (default: RTX_PORT or defaultPort)
|
|
238
|
+
* @param maxAttempts - Maximum ports to try (default: 100)
|
|
239
|
+
* @returns Promise resolving to an available port number
|
|
240
|
+
* @throws Error if no available port found in range
|
|
241
|
+
*/
|
|
242
|
+
async findAvailablePort(startPort, maxAttempts = 100) {
|
|
243
|
+
const port = startPort ?? this.getSuggestedPort();
|
|
244
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
245
|
+
const currentPort = port + i;
|
|
246
|
+
if (await this.isPortAvailable(currentPort)) {
|
|
247
|
+
return currentPort;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
throw new Error(`No available port found in range ${port}-${port + maxAttempts - 1}`);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Get a ready-to-use port
|
|
254
|
+
* Returns the suggested port if available, otherwise finds the next available port
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const sdk = new RealtimeXSDK();
|
|
259
|
+
* const port = await sdk.port.getPort();
|
|
260
|
+
* app.listen(port);
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
async getPort() {
|
|
264
|
+
const suggested = this.getSuggestedPort();
|
|
265
|
+
if (await this.isPortAvailable(suggested)) {
|
|
266
|
+
return suggested;
|
|
267
|
+
}
|
|
268
|
+
return this.findAvailablePort(suggested + 1);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
206
272
|
// src/index.ts
|
|
207
273
|
var _RealtimeXSDK = class _RealtimeXSDK {
|
|
208
274
|
constructor(config = {}) {
|
|
@@ -215,6 +281,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
215
281
|
this.webhook = new WebhookModule(realtimexUrl, this.appName, this.appId);
|
|
216
282
|
this.api = new ApiModule(realtimexUrl);
|
|
217
283
|
this.task = new TaskModule(realtimexUrl, this.appName, this.appId);
|
|
284
|
+
this.port = new PortModule(config.defaultPort);
|
|
218
285
|
}
|
|
219
286
|
/**
|
|
220
287
|
* Get environment variable (works in Node.js and browser)
|
|
@@ -234,6 +301,7 @@ var RealtimeXSDK = _RealtimeXSDK;
|
|
|
234
301
|
export {
|
|
235
302
|
ActivitiesModule,
|
|
236
303
|
ApiModule,
|
|
304
|
+
PortModule,
|
|
237
305
|
RealtimeXSDK,
|
|
238
306
|
TaskModule,
|
|
239
307
|
WebhookModule
|