@realtimex/sdk 1.0.4 → 1.0.5

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 CHANGED
@@ -143,6 +143,36 @@ declare class ApiModule {
143
143
  getTask(taskUuid: string): Promise<Task>;
144
144
  }
145
145
 
146
+ /**
147
+ * Task Module - Report task status to RealtimeX
148
+ * Used by external agents/processors to update task status
149
+ */
150
+ interface TaskStatusResponse {
151
+ success: boolean;
152
+ task_uuid: string;
153
+ status: string;
154
+ message?: string;
155
+ }
156
+ declare class TaskModule {
157
+ private realtimexUrl;
158
+ private appName?;
159
+ private appId?;
160
+ constructor(realtimexUrl: string, appName?: string, appId?: string);
161
+ /**
162
+ * Mark task as processing
163
+ */
164
+ start(taskUuid: string, machineId?: string): Promise<TaskStatusResponse>;
165
+ /**
166
+ * Mark task as completed with result
167
+ */
168
+ complete(taskUuid: string, result?: object, machineId?: string): Promise<TaskStatusResponse>;
169
+ /**
170
+ * Mark task as failed with error
171
+ */
172
+ fail(taskUuid: string, error: string, machineId?: string): Promise<TaskStatusResponse>;
173
+ private _sendEvent;
174
+ }
175
+
146
176
  /**
147
177
  * RealtimeX Local App SDK
148
178
  *
@@ -154,6 +184,7 @@ declare class RealtimeXSDK {
154
184
  activities: ActivitiesModule;
155
185
  webhook: WebhookModule;
156
186
  api: ApiModule;
187
+ task: TaskModule;
157
188
  readonly appId: string;
158
189
  readonly appName: string | undefined;
159
190
  private static DEFAULT_REALTIMEX_URL;
@@ -164,4 +195,4 @@ declare class RealtimeXSDK {
164
195
  private getEnvVar;
165
196
  }
166
197
 
167
- export { ActivitiesModule, type Activity, type Agent, ApiModule, RealtimeXSDK, type SDKConfig, type Task, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, WebhookModule, type Workspace };
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 };
package/dist/index.d.ts CHANGED
@@ -143,6 +143,36 @@ declare class ApiModule {
143
143
  getTask(taskUuid: string): Promise<Task>;
144
144
  }
145
145
 
146
+ /**
147
+ * Task Module - Report task status to RealtimeX
148
+ * Used by external agents/processors to update task status
149
+ */
150
+ interface TaskStatusResponse {
151
+ success: boolean;
152
+ task_uuid: string;
153
+ status: string;
154
+ message?: string;
155
+ }
156
+ declare class TaskModule {
157
+ private realtimexUrl;
158
+ private appName?;
159
+ private appId?;
160
+ constructor(realtimexUrl: string, appName?: string, appId?: string);
161
+ /**
162
+ * Mark task as processing
163
+ */
164
+ start(taskUuid: string, machineId?: string): Promise<TaskStatusResponse>;
165
+ /**
166
+ * Mark task as completed with result
167
+ */
168
+ complete(taskUuid: string, result?: object, machineId?: string): Promise<TaskStatusResponse>;
169
+ /**
170
+ * Mark task as failed with error
171
+ */
172
+ fail(taskUuid: string, error: string, machineId?: string): Promise<TaskStatusResponse>;
173
+ private _sendEvent;
174
+ }
175
+
146
176
  /**
147
177
  * RealtimeX Local App SDK
148
178
  *
@@ -154,6 +184,7 @@ declare class RealtimeXSDK {
154
184
  activities: ActivitiesModule;
155
185
  webhook: WebhookModule;
156
186
  api: ApiModule;
187
+ task: TaskModule;
157
188
  readonly appId: string;
158
189
  readonly appName: string | undefined;
159
190
  private static DEFAULT_REALTIMEX_URL;
@@ -164,4 +195,4 @@ declare class RealtimeXSDK {
164
195
  private getEnvVar;
165
196
  }
166
197
 
167
- export { ActivitiesModule, type Activity, type Agent, ApiModule, RealtimeXSDK, type SDKConfig, type Task, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, WebhookModule, type Workspace };
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 };
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  ActivitiesModule: () => ActivitiesModule,
24
24
  ApiModule: () => ApiModule,
25
25
  RealtimeXSDK: () => RealtimeXSDK,
26
+ TaskModule: () => TaskModule,
26
27
  WebhookModule: () => WebhookModule
27
28
  });
28
29
  module.exports = __toCommonJS(index_exports);
@@ -187,6 +188,51 @@ var ApiModule = class {
187
188
  }
188
189
  };
189
190
 
191
+ // src/modules/task.ts
192
+ var TaskModule = class {
193
+ constructor(realtimexUrl, appName, appId) {
194
+ this.realtimexUrl = realtimexUrl.replace(/\/$/, "");
195
+ this.appName = appName;
196
+ this.appId = appId;
197
+ }
198
+ /**
199
+ * Mark task as processing
200
+ */
201
+ async start(taskUuid, machineId) {
202
+ return this._sendEvent("task-start", taskUuid, { machine_id: machineId });
203
+ }
204
+ /**
205
+ * Mark task as completed with result
206
+ */
207
+ async complete(taskUuid, result, machineId) {
208
+ return this._sendEvent("task-complete", taskUuid, { result, machine_id: machineId });
209
+ }
210
+ /**
211
+ * Mark task as failed with error
212
+ */
213
+ async fail(taskUuid, error, machineId) {
214
+ return this._sendEvent("task-fail", taskUuid, { error, machine_id: machineId });
215
+ }
216
+ async _sendEvent(event, taskUuid, extra) {
217
+ const response = await fetch(`${this.realtimexUrl}/webhooks/realtimex`, {
218
+ method: "POST",
219
+ headers: { "Content-Type": "application/json" },
220
+ body: JSON.stringify({
221
+ app_name: this.appName,
222
+ app_id: this.appId,
223
+ event,
224
+ payload: {
225
+ task_uuid: taskUuid,
226
+ ...extra
227
+ }
228
+ })
229
+ });
230
+ const data = await response.json();
231
+ if (!response.ok) throw new Error(data.error || `Failed to ${event}`);
232
+ return data;
233
+ }
234
+ };
235
+
190
236
  // src/index.ts
191
237
  var _RealtimeXSDK = class _RealtimeXSDK {
192
238
  constructor(config = {}) {
@@ -198,6 +244,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
198
244
  this.activities = new ActivitiesModule(realtimexUrl, this.appId);
199
245
  this.webhook = new WebhookModule(realtimexUrl, this.appName, this.appId);
200
246
  this.api = new ApiModule(realtimexUrl);
247
+ this.task = new TaskModule(realtimexUrl, this.appName, this.appId);
201
248
  }
202
249
  /**
203
250
  * Get environment variable (works in Node.js and browser)
@@ -219,5 +266,6 @@ var RealtimeXSDK = _RealtimeXSDK;
219
266
  ActivitiesModule,
220
267
  ApiModule,
221
268
  RealtimeXSDK,
269
+ TaskModule,
222
270
  WebhookModule
223
271
  });
package/dist/index.mjs CHANGED
@@ -158,6 +158,51 @@ var ApiModule = class {
158
158
  }
159
159
  };
160
160
 
161
+ // src/modules/task.ts
162
+ var TaskModule = class {
163
+ constructor(realtimexUrl, appName, appId) {
164
+ this.realtimexUrl = realtimexUrl.replace(/\/$/, "");
165
+ this.appName = appName;
166
+ this.appId = appId;
167
+ }
168
+ /**
169
+ * Mark task as processing
170
+ */
171
+ async start(taskUuid, machineId) {
172
+ return this._sendEvent("task-start", taskUuid, { machine_id: machineId });
173
+ }
174
+ /**
175
+ * Mark task as completed with result
176
+ */
177
+ async complete(taskUuid, result, machineId) {
178
+ return this._sendEvent("task-complete", taskUuid, { result, machine_id: machineId });
179
+ }
180
+ /**
181
+ * Mark task as failed with error
182
+ */
183
+ async fail(taskUuid, error, machineId) {
184
+ return this._sendEvent("task-fail", taskUuid, { error, machine_id: machineId });
185
+ }
186
+ async _sendEvent(event, taskUuid, extra) {
187
+ const response = await fetch(`${this.realtimexUrl}/webhooks/realtimex`, {
188
+ method: "POST",
189
+ headers: { "Content-Type": "application/json" },
190
+ body: JSON.stringify({
191
+ app_name: this.appName,
192
+ app_id: this.appId,
193
+ event,
194
+ payload: {
195
+ task_uuid: taskUuid,
196
+ ...extra
197
+ }
198
+ })
199
+ });
200
+ const data = await response.json();
201
+ if (!response.ok) throw new Error(data.error || `Failed to ${event}`);
202
+ return data;
203
+ }
204
+ };
205
+
161
206
  // src/index.ts
162
207
  var _RealtimeXSDK = class _RealtimeXSDK {
163
208
  constructor(config = {}) {
@@ -169,6 +214,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
169
214
  this.activities = new ActivitiesModule(realtimexUrl, this.appId);
170
215
  this.webhook = new WebhookModule(realtimexUrl, this.appName, this.appId);
171
216
  this.api = new ApiModule(realtimexUrl);
217
+ this.task = new TaskModule(realtimexUrl, this.appName, this.appId);
172
218
  }
173
219
  /**
174
220
  * Get environment variable (works in Node.js and browser)
@@ -189,5 +235,6 @@ export {
189
235
  ActivitiesModule,
190
236
  ApiModule,
191
237
  RealtimeXSDK,
238
+ TaskModule,
192
239
  WebhookModule
193
240
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realtimex/sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "SDK for building Local Apps that integrate with RealtimeX",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",