@robosystems/client 2.2.3 → 2.2.4

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.
@@ -95,6 +95,16 @@ export declare class OperatorClient {
95
95
  */
96
96
  close(): void;
97
97
  }
98
+ /**
99
+ * A run that failed or was cancelled. `writes` lists what it had already
100
+ * changed on the graph before it stopped, so a caller can show a receipt
101
+ * rather than invite a retry that repeats them.
102
+ */
103
+ export declare class OperatorRunError extends Error {
104
+ status: 'failed' | 'cancelled';
105
+ writes: Record<string, any>[];
106
+ constructor(message: string, status: 'failed' | 'cancelled', writes: Record<string, any>[]);
107
+ }
98
108
  /**
99
109
  * Error thrown when agent execution is queued and maxWait is 0
100
110
  */
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.QueuedOperatorError = exports.OperatorClient = void 0;
4
+ exports.QueuedOperatorError = exports.OperatorRunError = exports.OperatorClient = void 0;
5
5
  /**
6
6
  * Enhanced AI Operator Client with SSE support
7
7
  * Provides intelligent operator execution with automatic strategy selection
@@ -167,11 +167,11 @@ class OperatorClient {
167
167
  });
168
168
  sseClient.on(SSEClient_1.EventType.OPERATION_ERROR, (error) => {
169
169
  finish();
170
- reject(new Error(error.message || error.error));
170
+ reject(new OperatorRunError(error.message || error.error, 'failed', readWrites(error.error_details)));
171
171
  });
172
172
  sseClient.on(SSEClient_1.EventType.OPERATION_CANCELLED, () => {
173
173
  finish();
174
- reject(new Error('Agent execution cancelled'));
174
+ reject(new OperatorRunError('Agent execution cancelled', 'cancelled', []));
175
175
  });
176
176
  // Handle generic error event
177
177
  sseClient.on('error', (error) => {
@@ -225,9 +225,9 @@ class OperatorClient {
225
225
  case 'completed':
226
226
  return toOperatorResult(status.result || {});
227
227
  case 'failed':
228
- throw new Error(status.error || status.message || 'Operator run failed');
228
+ throw new OperatorRunError(status.error || status.message || 'Operator run failed', 'failed', readWrites(status));
229
229
  case 'cancelled':
230
- throw new Error('Agent execution cancelled');
230
+ throw new OperatorRunError('Agent execution cancelled', 'cancelled', readWrites(status.result));
231
231
  default:
232
232
  if (status.message) {
233
233
  options.onProgress?.(status.message);
@@ -253,6 +253,26 @@ class OperatorClient {
253
253
  }
254
254
  }
255
255
  exports.OperatorClient = OperatorClient;
256
+ /**
257
+ * A run that failed or was cancelled. `writes` lists what it had already
258
+ * changed on the graph before it stopped, so a caller can show a receipt
259
+ * rather than invite a retry that repeats them.
260
+ */
261
+ class OperatorRunError extends Error {
262
+ constructor(message, status, writes) {
263
+ super(message);
264
+ this.status = status;
265
+ this.writes = writes;
266
+ this.name = 'OperatorRunError';
267
+ }
268
+ }
269
+ exports.OperatorRunError = OperatorRunError;
270
+ const readWrites = (source) => {
271
+ const writes = source?.writes;
272
+ return Array.isArray(writes)
273
+ ? writes.filter((w) => !!w && typeof w === 'object')
274
+ : [];
275
+ };
256
276
  /**
257
277
  * Error thrown when agent execution is queued and maxWait is 0
258
278
  */
@@ -271,12 +271,18 @@ export class OperatorClient {
271
271
 
272
272
  sseClient.on(EventType.OPERATION_ERROR, (error) => {
273
273
  finish()
274
- reject(new Error(error.message || error.error))
274
+ reject(
275
+ new OperatorRunError(
276
+ error.message || error.error,
277
+ 'failed',
278
+ readWrites(error.error_details)
279
+ )
280
+ )
275
281
  })
276
282
 
277
283
  sseClient.on(EventType.OPERATION_CANCELLED, () => {
278
284
  finish()
279
- reject(new Error('Agent execution cancelled'))
285
+ reject(new OperatorRunError('Agent execution cancelled', 'cancelled', []))
280
286
  })
281
287
 
282
288
  // Handle generic error event
@@ -345,9 +351,17 @@ export class OperatorClient {
345
351
  case 'completed':
346
352
  return toOperatorResult(status.result || {})
347
353
  case 'failed':
348
- throw new Error(status.error || status.message || 'Operator run failed')
354
+ throw new OperatorRunError(
355
+ status.error || status.message || 'Operator run failed',
356
+ 'failed',
357
+ readWrites(status)
358
+ )
349
359
  case 'cancelled':
350
- throw new Error('Agent execution cancelled')
360
+ throw new OperatorRunError(
361
+ 'Agent execution cancelled',
362
+ 'cancelled',
363
+ readWrites(status.result)
364
+ )
351
365
  default:
352
366
  if (status.message) {
353
367
  options.onProgress?.(status.message)
@@ -379,6 +393,29 @@ export class OperatorClient {
379
393
  }
380
394
  }
381
395
 
396
+ /**
397
+ * A run that failed or was cancelled. `writes` lists what it had already
398
+ * changed on the graph before it stopped, so a caller can show a receipt
399
+ * rather than invite a retry that repeats them.
400
+ */
401
+ export class OperatorRunError extends Error {
402
+ constructor(
403
+ message: string,
404
+ public status: 'failed' | 'cancelled',
405
+ public writes: Record<string, any>[]
406
+ ) {
407
+ super(message)
408
+ this.name = 'OperatorRunError'
409
+ }
410
+ }
411
+
412
+ const readWrites = (source: unknown): Record<string, any>[] => {
413
+ const writes = (source as { writes?: unknown } | null | undefined)?.writes
414
+ return Array.isArray(writes)
415
+ ? writes.filter((w): w is Record<string, any> => !!w && typeof w === 'object')
416
+ : []
417
+ }
418
+
382
419
  /**
383
420
  * Error thrown when agent execution is queued and maxWait is 0
384
421
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robosystems/client",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "TypeScript client library for the RoboSystems financial intelligence platform",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",