@realtimex/sdk 1.0.6 → 1.0.8
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 +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +37 -11
- package/dist/index.mjs +37 -11
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -137,7 +137,9 @@ declare class WebhookModule {
|
|
|
137
137
|
|
|
138
138
|
declare class ApiModule {
|
|
139
139
|
private realtimexUrl;
|
|
140
|
-
|
|
140
|
+
private appId;
|
|
141
|
+
constructor(realtimexUrl: string, appId: string);
|
|
142
|
+
private getHeaders;
|
|
141
143
|
getAgents(): Promise<Agent[]>;
|
|
142
144
|
getWorkspaces(): Promise<Workspace[]>;
|
|
143
145
|
getThreads(workspaceSlug: string): Promise<Thread[]>;
|
|
@@ -186,9 +188,13 @@ declare class PortModule {
|
|
|
186
188
|
*/
|
|
187
189
|
getSuggestedPort(): number;
|
|
188
190
|
/**
|
|
189
|
-
* Check if a port is available
|
|
191
|
+
* Check if a port is available on a specific host
|
|
192
|
+
*/
|
|
193
|
+
private isPortAvailableOn;
|
|
194
|
+
/**
|
|
195
|
+
* Check if a port is available (checks both IPv4 and IPv6)
|
|
190
196
|
* @param port - Port number to check
|
|
191
|
-
* @returns Promise resolving to true if port is available
|
|
197
|
+
* @returns Promise resolving to true if port is available on ALL interfaces
|
|
192
198
|
*/
|
|
193
199
|
isPortAvailable(port: number): Promise<boolean>;
|
|
194
200
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -137,7 +137,9 @@ declare class WebhookModule {
|
|
|
137
137
|
|
|
138
138
|
declare class ApiModule {
|
|
139
139
|
private realtimexUrl;
|
|
140
|
-
|
|
140
|
+
private appId;
|
|
141
|
+
constructor(realtimexUrl: string, appId: string);
|
|
142
|
+
private getHeaders;
|
|
141
143
|
getAgents(): Promise<Agent[]>;
|
|
142
144
|
getWorkspaces(): Promise<Workspace[]>;
|
|
143
145
|
getThreads(workspaceSlug: string): Promise<Thread[]>;
|
|
@@ -186,9 +188,13 @@ declare class PortModule {
|
|
|
186
188
|
*/
|
|
187
189
|
getSuggestedPort(): number;
|
|
188
190
|
/**
|
|
189
|
-
* Check if a port is available
|
|
191
|
+
* Check if a port is available on a specific host
|
|
192
|
+
*/
|
|
193
|
+
private isPortAvailableOn;
|
|
194
|
+
/**
|
|
195
|
+
* Check if a port is available (checks both IPv4 and IPv6)
|
|
190
196
|
* @param port - Port number to check
|
|
191
|
-
* @returns Promise resolving to true if port is available
|
|
197
|
+
* @returns Promise resolving to true if port is available on ALL interfaces
|
|
192
198
|
*/
|
|
193
199
|
isPortAvailable(port: number): Promise<boolean>;
|
|
194
200
|
/**
|
package/dist/index.js
CHANGED
|
@@ -170,29 +170,44 @@ var WebhookModule = class {
|
|
|
170
170
|
|
|
171
171
|
// src/modules/api.ts
|
|
172
172
|
var ApiModule = class {
|
|
173
|
-
constructor(realtimexUrl) {
|
|
173
|
+
constructor(realtimexUrl, appId) {
|
|
174
174
|
this.realtimexUrl = realtimexUrl.replace(/\/$/, "");
|
|
175
|
+
this.appId = appId;
|
|
176
|
+
}
|
|
177
|
+
getHeaders() {
|
|
178
|
+
return {
|
|
179
|
+
"Content-Type": "application/json",
|
|
180
|
+
"x-app-id": this.appId
|
|
181
|
+
};
|
|
175
182
|
}
|
|
176
183
|
async getAgents() {
|
|
177
|
-
const response = await fetch(`${this.realtimexUrl}/agents
|
|
184
|
+
const response = await fetch(`${this.realtimexUrl}/agents`, {
|
|
185
|
+
headers: this.getHeaders()
|
|
186
|
+
});
|
|
178
187
|
const data = await response.json();
|
|
179
188
|
if (!response.ok) throw new Error(data.error || "Failed to get agents");
|
|
180
189
|
return data.agents;
|
|
181
190
|
}
|
|
182
191
|
async getWorkspaces() {
|
|
183
|
-
const response = await fetch(`${this.realtimexUrl}/workspaces
|
|
192
|
+
const response = await fetch(`${this.realtimexUrl}/workspaces`, {
|
|
193
|
+
headers: this.getHeaders()
|
|
194
|
+
});
|
|
184
195
|
const data = await response.json();
|
|
185
196
|
if (!response.ok) throw new Error(data.error || "Failed to get workspaces");
|
|
186
197
|
return data.workspaces;
|
|
187
198
|
}
|
|
188
199
|
async getThreads(workspaceSlug) {
|
|
189
|
-
const response = await fetch(`${this.realtimexUrl}/workspaces/${encodeURIComponent(workspaceSlug)}/threads
|
|
200
|
+
const response = await fetch(`${this.realtimexUrl}/workspaces/${encodeURIComponent(workspaceSlug)}/threads`, {
|
|
201
|
+
headers: this.getHeaders()
|
|
202
|
+
});
|
|
190
203
|
const data = await response.json();
|
|
191
204
|
if (!response.ok) throw new Error(data.error || "Failed to get threads");
|
|
192
205
|
return data.threads;
|
|
193
206
|
}
|
|
194
207
|
async getTask(taskUuid) {
|
|
195
|
-
const response = await fetch(`${this.realtimexUrl}/task/${encodeURIComponent(taskUuid)}
|
|
208
|
+
const response = await fetch(`${this.realtimexUrl}/task/${encodeURIComponent(taskUuid)}`, {
|
|
209
|
+
headers: this.getHeaders()
|
|
210
|
+
});
|
|
196
211
|
const data = await response.json();
|
|
197
212
|
if (!response.ok) throw new Error(data.error || "Failed to get task");
|
|
198
213
|
return { ...data.task, runs: data.runs };
|
|
@@ -258,11 +273,9 @@ var PortModule = class {
|
|
|
258
273
|
return envPort ? parseInt(envPort, 10) : this.defaultPort;
|
|
259
274
|
}
|
|
260
275
|
/**
|
|
261
|
-
* Check if a port is available
|
|
262
|
-
* @param port - Port number to check
|
|
263
|
-
* @returns Promise resolving to true if port is available
|
|
276
|
+
* Check if a port is available on a specific host
|
|
264
277
|
*/
|
|
265
|
-
async
|
|
278
|
+
async isPortAvailableOn(port, host) {
|
|
266
279
|
return new Promise((resolve) => {
|
|
267
280
|
const server = net.createServer();
|
|
268
281
|
server.once("error", () => resolve(false));
|
|
@@ -270,9 +283,22 @@ var PortModule = class {
|
|
|
270
283
|
server.close();
|
|
271
284
|
resolve(true);
|
|
272
285
|
});
|
|
273
|
-
server.listen(port,
|
|
286
|
+
server.listen(port, host);
|
|
274
287
|
});
|
|
275
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Check if a port is available (checks both IPv4 and IPv6)
|
|
291
|
+
* @param port - Port number to check
|
|
292
|
+
* @returns Promise resolving to true if port is available on ALL interfaces
|
|
293
|
+
*/
|
|
294
|
+
async isPortAvailable(port) {
|
|
295
|
+
const ipv4Available = await this.isPortAvailableOn(port, "127.0.0.1");
|
|
296
|
+
if (!ipv4Available) return false;
|
|
297
|
+
const ipv6Available = await this.isPortAvailableOn(port, "::1");
|
|
298
|
+
if (!ipv6Available) return false;
|
|
299
|
+
const allInterfacesAvailable = await this.isPortAvailableOn(port, "0.0.0.0");
|
|
300
|
+
return allInterfacesAvailable;
|
|
301
|
+
}
|
|
276
302
|
/**
|
|
277
303
|
* Find an available port starting from the suggested port
|
|
278
304
|
* @param startPort - Starting port number (default: RTX_PORT or defaultPort)
|
|
@@ -320,7 +346,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
320
346
|
const realtimexUrl = config.realtimex?.url || _RealtimeXSDK.DEFAULT_REALTIMEX_URL;
|
|
321
347
|
this.activities = new ActivitiesModule(realtimexUrl, this.appId);
|
|
322
348
|
this.webhook = new WebhookModule(realtimexUrl, this.appName, this.appId);
|
|
323
|
-
this.api = new ApiModule(realtimexUrl);
|
|
349
|
+
this.api = new ApiModule(realtimexUrl, this.appId);
|
|
324
350
|
this.task = new TaskModule(realtimexUrl, this.appName, this.appId);
|
|
325
351
|
this.port = new PortModule(config.defaultPort);
|
|
326
352
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -129,29 +129,44 @@ var WebhookModule = class {
|
|
|
129
129
|
|
|
130
130
|
// src/modules/api.ts
|
|
131
131
|
var ApiModule = class {
|
|
132
|
-
constructor(realtimexUrl) {
|
|
132
|
+
constructor(realtimexUrl, appId) {
|
|
133
133
|
this.realtimexUrl = realtimexUrl.replace(/\/$/, "");
|
|
134
|
+
this.appId = appId;
|
|
135
|
+
}
|
|
136
|
+
getHeaders() {
|
|
137
|
+
return {
|
|
138
|
+
"Content-Type": "application/json",
|
|
139
|
+
"x-app-id": this.appId
|
|
140
|
+
};
|
|
134
141
|
}
|
|
135
142
|
async getAgents() {
|
|
136
|
-
const response = await fetch(`${this.realtimexUrl}/agents
|
|
143
|
+
const response = await fetch(`${this.realtimexUrl}/agents`, {
|
|
144
|
+
headers: this.getHeaders()
|
|
145
|
+
});
|
|
137
146
|
const data = await response.json();
|
|
138
147
|
if (!response.ok) throw new Error(data.error || "Failed to get agents");
|
|
139
148
|
return data.agents;
|
|
140
149
|
}
|
|
141
150
|
async getWorkspaces() {
|
|
142
|
-
const response = await fetch(`${this.realtimexUrl}/workspaces
|
|
151
|
+
const response = await fetch(`${this.realtimexUrl}/workspaces`, {
|
|
152
|
+
headers: this.getHeaders()
|
|
153
|
+
});
|
|
143
154
|
const data = await response.json();
|
|
144
155
|
if (!response.ok) throw new Error(data.error || "Failed to get workspaces");
|
|
145
156
|
return data.workspaces;
|
|
146
157
|
}
|
|
147
158
|
async getThreads(workspaceSlug) {
|
|
148
|
-
const response = await fetch(`${this.realtimexUrl}/workspaces/${encodeURIComponent(workspaceSlug)}/threads
|
|
159
|
+
const response = await fetch(`${this.realtimexUrl}/workspaces/${encodeURIComponent(workspaceSlug)}/threads`, {
|
|
160
|
+
headers: this.getHeaders()
|
|
161
|
+
});
|
|
149
162
|
const data = await response.json();
|
|
150
163
|
if (!response.ok) throw new Error(data.error || "Failed to get threads");
|
|
151
164
|
return data.threads;
|
|
152
165
|
}
|
|
153
166
|
async getTask(taskUuid) {
|
|
154
|
-
const response = await fetch(`${this.realtimexUrl}/task/${encodeURIComponent(taskUuid)}
|
|
167
|
+
const response = await fetch(`${this.realtimexUrl}/task/${encodeURIComponent(taskUuid)}`, {
|
|
168
|
+
headers: this.getHeaders()
|
|
169
|
+
});
|
|
155
170
|
const data = await response.json();
|
|
156
171
|
if (!response.ok) throw new Error(data.error || "Failed to get task");
|
|
157
172
|
return { ...data.task, runs: data.runs };
|
|
@@ -217,11 +232,9 @@ var PortModule = class {
|
|
|
217
232
|
return envPort ? parseInt(envPort, 10) : this.defaultPort;
|
|
218
233
|
}
|
|
219
234
|
/**
|
|
220
|
-
* Check if a port is available
|
|
221
|
-
* @param port - Port number to check
|
|
222
|
-
* @returns Promise resolving to true if port is available
|
|
235
|
+
* Check if a port is available on a specific host
|
|
223
236
|
*/
|
|
224
|
-
async
|
|
237
|
+
async isPortAvailableOn(port, host) {
|
|
225
238
|
return new Promise((resolve) => {
|
|
226
239
|
const server = net.createServer();
|
|
227
240
|
server.once("error", () => resolve(false));
|
|
@@ -229,9 +242,22 @@ var PortModule = class {
|
|
|
229
242
|
server.close();
|
|
230
243
|
resolve(true);
|
|
231
244
|
});
|
|
232
|
-
server.listen(port,
|
|
245
|
+
server.listen(port, host);
|
|
233
246
|
});
|
|
234
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Check if a port is available (checks both IPv4 and IPv6)
|
|
250
|
+
* @param port - Port number to check
|
|
251
|
+
* @returns Promise resolving to true if port is available on ALL interfaces
|
|
252
|
+
*/
|
|
253
|
+
async isPortAvailable(port) {
|
|
254
|
+
const ipv4Available = await this.isPortAvailableOn(port, "127.0.0.1");
|
|
255
|
+
if (!ipv4Available) return false;
|
|
256
|
+
const ipv6Available = await this.isPortAvailableOn(port, "::1");
|
|
257
|
+
if (!ipv6Available) return false;
|
|
258
|
+
const allInterfacesAvailable = await this.isPortAvailableOn(port, "0.0.0.0");
|
|
259
|
+
return allInterfacesAvailable;
|
|
260
|
+
}
|
|
235
261
|
/**
|
|
236
262
|
* Find an available port starting from the suggested port
|
|
237
263
|
* @param startPort - Starting port number (default: RTX_PORT or defaultPort)
|
|
@@ -279,7 +305,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
279
305
|
const realtimexUrl = config.realtimex?.url || _RealtimeXSDK.DEFAULT_REALTIMEX_URL;
|
|
280
306
|
this.activities = new ActivitiesModule(realtimexUrl, this.appId);
|
|
281
307
|
this.webhook = new WebhookModule(realtimexUrl, this.appName, this.appId);
|
|
282
|
-
this.api = new ApiModule(realtimexUrl);
|
|
308
|
+
this.api = new ApiModule(realtimexUrl, this.appId);
|
|
283
309
|
this.task = new TaskModule(realtimexUrl, this.appName, this.appId);
|
|
284
310
|
this.port = new PortModule(config.defaultPort);
|
|
285
311
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realtimex/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "SDK for building Local Apps that integrate with RealtimeX",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -40,4 +40,4 @@
|
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=18.0.0"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|