@uipath/uipath-typescript 1.3.10 → 1.4.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.
Files changed (56) hide show
  1. package/dist/agent-memory/index.cjs +1765 -0
  2. package/dist/agent-memory/index.d.ts +588 -0
  3. package/dist/agent-memory/index.mjs +1763 -0
  4. package/dist/agents/index.cjs +1726 -0
  5. package/dist/agents/index.d.ts +502 -0
  6. package/dist/agents/index.mjs +1724 -0
  7. package/dist/assets/index.cjs +155 -30
  8. package/dist/assets/index.d.ts +84 -5
  9. package/dist/assets/index.mjs +155 -30
  10. package/dist/attachments/index.cjs +37 -6
  11. package/dist/attachments/index.d.ts +1 -0
  12. package/dist/attachments/index.mjs +37 -6
  13. package/dist/buckets/index.cjs +37 -6
  14. package/dist/buckets/index.d.ts +1 -0
  15. package/dist/buckets/index.mjs +37 -6
  16. package/dist/cases/index.cjs +192 -10
  17. package/dist/cases/index.d.ts +208 -7
  18. package/dist/cases/index.mjs +192 -11
  19. package/dist/conversational-agent/index.cjs +124 -57
  20. package/dist/conversational-agent/index.d.ts +190 -122
  21. package/dist/conversational-agent/index.mjs +124 -57
  22. package/dist/core/index.cjs +413 -105
  23. package/dist/core/index.d.ts +15 -0
  24. package/dist/core/index.mjs +413 -105
  25. package/dist/entities/index.cjs +135 -70
  26. package/dist/entities/index.d.ts +146 -45
  27. package/dist/entities/index.mjs +135 -70
  28. package/dist/feedback/index.cjs +37 -6
  29. package/dist/feedback/index.d.ts +1 -0
  30. package/dist/feedback/index.mjs +37 -6
  31. package/dist/governance/index.cjs +1782 -0
  32. package/dist/governance/index.d.ts +598 -0
  33. package/dist/governance/index.mjs +1780 -0
  34. package/dist/index.cjs +1050 -291
  35. package/dist/index.d.ts +1313 -134
  36. package/dist/index.mjs +1050 -292
  37. package/dist/index.umd.js +4546 -3770
  38. package/dist/jobs/index.cjs +37 -6
  39. package/dist/jobs/index.d.ts +1 -0
  40. package/dist/jobs/index.mjs +37 -6
  41. package/dist/maestro-processes/index.cjs +224 -18
  42. package/dist/maestro-processes/index.d.ts +221 -9
  43. package/dist/maestro-processes/index.mjs +224 -18
  44. package/dist/processes/index.cjs +37 -6
  45. package/dist/processes/index.d.ts +1 -0
  46. package/dist/processes/index.mjs +37 -6
  47. package/dist/queues/index.cjs +37 -6
  48. package/dist/queues/index.d.ts +1 -0
  49. package/dist/queues/index.mjs +37 -6
  50. package/dist/tasks/index.cjs +37 -6
  51. package/dist/tasks/index.d.ts +1 -0
  52. package/dist/tasks/index.mjs +37 -6
  53. package/dist/traces/index.cjs +1933 -0
  54. package/dist/traces/index.d.ts +566 -0
  55. package/dist/traces/index.mjs +1931 -0
  56. package/package.json +42 -2
@@ -721,6 +721,32 @@ function filterUndefined(obj) {
721
721
  */
722
722
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
723
723
  isBrowser && window.self != window.top && window.location.href.includes('source=ActionCenter');
724
+ const _params = isBrowser ? new URLSearchParams(window.location.search) : null;
725
+ /**
726
+ * True when the coded app has been loaded inside a host frame that explicitly
727
+ * opted into token delegation by adding `?host=embed` to the iframe src URL.
728
+ */
729
+ const isHostEmbedded = isBrowser && window.self !== window.top && _params?.get('host') === 'embed';
730
+ /**
731
+ * The validated parent origin, read from the `?basedomain=` query param set
732
+ * by the embedding host in the iframe src URL.
733
+ * Mirrors the same mechanism used by ActionCenterTokenManager.
734
+ * Non-null only when `?host=embed` is present and `?basedomain=` is a valid URL.
735
+ */
736
+ (() => {
737
+ if (!isHostEmbedded)
738
+ return null;
739
+ const basedomain = _params?.get('basedomain');
740
+ if (!basedomain)
741
+ return null;
742
+ try {
743
+ return new URL(basedomain).origin;
744
+ }
745
+ catch {
746
+ console.warn('embeddingOrigin: basedomain query param is not a valid URL', basedomain);
747
+ return null;
748
+ }
749
+ })();
724
750
 
725
751
  /**
726
752
  * Base64 encoding/decoding
@@ -1281,8 +1307,9 @@ class PaginationHelpers {
1281
1307
  });
1282
1308
  }
1283
1309
  // Extract and transform items from response
1284
- // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N })
1285
- const rawItems = Array.isArray(response.data) ? response.data : response.data?.[itemsField];
1310
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1311
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1312
+ const rawItems = Array.isArray(response.data) ? response.data : resolveNestedField(response.data, itemsField);
1286
1313
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1287
1314
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1288
1315
  // Parse items - automatically handle JSON string responses
@@ -1328,7 +1355,7 @@ class PaginationHelpers {
1328
1355
  getEndpoint: config.getEndpoint,
1329
1356
  folderId,
1330
1357
  headers: config.headers,
1331
- paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1358
+ paginationParams: cursor ? { cursor, pageSize } : jumpToPage !== undefined ? { jumpToPage, pageSize } : { pageSize },
1332
1359
  additionalParams: prefixedOptions,
1333
1360
  transformFn: config.transformFn,
1334
1361
  method: config.method,
@@ -1586,6 +1613,8 @@ class BaseService {
1586
1613
  // When true (default), converts pageNumber to a skip/offset value (e.g., page 3 with pageSize 10 → skip 20).
1587
1614
  // When false, passes pageNumber directly as the offset param — used by APIs that accept a page number instead of a record offset.
1588
1615
  const convertToSkip = paginationParams?.convertToSkip ?? true;
1616
+ // When true, sends pageNumber - 1 (for 0-based APIs). Default false (1-based).
1617
+ const zeroBased = paginationParams?.zeroBased ?? false;
1589
1618
  requestParams[pageSizeParam] = limitedPageSize;
1590
1619
  if (convertToSkip) {
1591
1620
  if (params.pageNumber && params.pageNumber > 1) {
@@ -1593,7 +1622,8 @@ class BaseService {
1593
1622
  }
1594
1623
  }
1595
1624
  else {
1596
- requestParams[offsetParam] = params.pageNumber || 1;
1625
+ const sdkPageNumber = params.pageNumber || 1;
1626
+ requestParams[offsetParam] = zeroBased ? sdkPageNumber - 1 : sdkPageNumber;
1597
1627
  }
1598
1628
  {
1599
1629
  requestParams[countParam] = true;
@@ -1622,8 +1652,9 @@ class BaseService {
1622
1652
  const totalCountField = fields.totalCountField || 'totalRecordCount';
1623
1653
  const continuationTokenField = fields.continuationTokenField || 'continuationToken';
1624
1654
  // Extract items and metadata
1625
- // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N })
1626
- const items = Array.isArray(response.data) ? response.data : (response.data[itemsField] || []);
1655
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1656
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1657
+ const items = Array.isArray(response.data) ? response.data : (resolveNestedField(response.data, itemsField) || []);
1627
1658
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1628
1659
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1629
1660
  const continuationToken = response.data[continuationTokenField];
@@ -107,6 +107,7 @@ interface RequestWithPaginationOptions extends RequestSpec {
107
107
  tokenParam?: string;
108
108
  countParam?: string;
109
109
  convertToSkip?: boolean;
110
+ zeroBased?: boolean;
110
111
  };
111
112
  };
112
113
  }
@@ -719,6 +719,32 @@ function filterUndefined(obj) {
719
719
  */
720
720
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
721
721
  isBrowser && window.self != window.top && window.location.href.includes('source=ActionCenter');
722
+ const _params = isBrowser ? new URLSearchParams(window.location.search) : null;
723
+ /**
724
+ * True when the coded app has been loaded inside a host frame that explicitly
725
+ * opted into token delegation by adding `?host=embed` to the iframe src URL.
726
+ */
727
+ const isHostEmbedded = isBrowser && window.self !== window.top && _params?.get('host') === 'embed';
728
+ /**
729
+ * The validated parent origin, read from the `?basedomain=` query param set
730
+ * by the embedding host in the iframe src URL.
731
+ * Mirrors the same mechanism used by ActionCenterTokenManager.
732
+ * Non-null only when `?host=embed` is present and `?basedomain=` is a valid URL.
733
+ */
734
+ (() => {
735
+ if (!isHostEmbedded)
736
+ return null;
737
+ const basedomain = _params?.get('basedomain');
738
+ if (!basedomain)
739
+ return null;
740
+ try {
741
+ return new URL(basedomain).origin;
742
+ }
743
+ catch {
744
+ console.warn('embeddingOrigin: basedomain query param is not a valid URL', basedomain);
745
+ return null;
746
+ }
747
+ })();
722
748
 
723
749
  /**
724
750
  * Base64 encoding/decoding
@@ -1279,8 +1305,9 @@ class PaginationHelpers {
1279
1305
  });
1280
1306
  }
1281
1307
  // Extract and transform items from response
1282
- // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N })
1283
- const rawItems = Array.isArray(response.data) ? response.data : response.data?.[itemsField];
1308
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1309
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1310
+ const rawItems = Array.isArray(response.data) ? response.data : resolveNestedField(response.data, itemsField);
1284
1311
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1285
1312
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1286
1313
  // Parse items - automatically handle JSON string responses
@@ -1326,7 +1353,7 @@ class PaginationHelpers {
1326
1353
  getEndpoint: config.getEndpoint,
1327
1354
  folderId,
1328
1355
  headers: config.headers,
1329
- paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1356
+ paginationParams: cursor ? { cursor, pageSize } : jumpToPage !== undefined ? { jumpToPage, pageSize } : { pageSize },
1330
1357
  additionalParams: prefixedOptions,
1331
1358
  transformFn: config.transformFn,
1332
1359
  method: config.method,
@@ -1584,6 +1611,8 @@ class BaseService {
1584
1611
  // When true (default), converts pageNumber to a skip/offset value (e.g., page 3 with pageSize 10 → skip 20).
1585
1612
  // When false, passes pageNumber directly as the offset param — used by APIs that accept a page number instead of a record offset.
1586
1613
  const convertToSkip = paginationParams?.convertToSkip ?? true;
1614
+ // When true, sends pageNumber - 1 (for 0-based APIs). Default false (1-based).
1615
+ const zeroBased = paginationParams?.zeroBased ?? false;
1587
1616
  requestParams[pageSizeParam] = limitedPageSize;
1588
1617
  if (convertToSkip) {
1589
1618
  if (params.pageNumber && params.pageNumber > 1) {
@@ -1591,7 +1620,8 @@ class BaseService {
1591
1620
  }
1592
1621
  }
1593
1622
  else {
1594
- requestParams[offsetParam] = params.pageNumber || 1;
1623
+ const sdkPageNumber = params.pageNumber || 1;
1624
+ requestParams[offsetParam] = zeroBased ? sdkPageNumber - 1 : sdkPageNumber;
1595
1625
  }
1596
1626
  {
1597
1627
  requestParams[countParam] = true;
@@ -1620,8 +1650,9 @@ class BaseService {
1620
1650
  const totalCountField = fields.totalCountField || 'totalRecordCount';
1621
1651
  const continuationTokenField = fields.continuationTokenField || 'continuationToken';
1622
1652
  // Extract items and metadata
1623
- // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N })
1624
- const items = Array.isArray(response.data) ? response.data : (response.data[itemsField] || []);
1653
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1654
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1655
+ const items = Array.isArray(response.data) ? response.data : (resolveNestedField(response.data, itemsField) || []);
1625
1656
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1626
1657
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1627
1658
  const continuationToken = response.data[continuationTokenField];
@@ -48,6 +48,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
48
48
  * Base path constants for different services
49
49
  */
50
50
  const PIMS_BASE = 'pims_';
51
+ const LLMOPS_BASE = 'llmopstenant_';
51
52
  const INSIGHTS_RTM_BASE = 'insightsrtm_';
52
53
 
53
54
  /**
@@ -62,7 +63,7 @@ const MAESTRO_ENDPOINTS = {
62
63
  INSTANCES: {
63
64
  GET_ALL: `${PIMS_BASE}/api/v1/instances`,
64
65
  GET_BY_ID: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}`,
65
- GET_EXECUTION_HISTORY: (instanceId) => `${PIMS_BASE}/api/v1/spans/${instanceId}`,
66
+ GET_ELEMENT_EXECUTIONS: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/element-executions`,
66
67
  GET_BPMN: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/bpmn`,
67
68
  GET_VARIABLES: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/variables`,
68
69
  CANCEL: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/cancel`,
@@ -74,15 +75,22 @@ const MAESTRO_ENDPOINTS = {
74
75
  GET_BY_PROCESS: (processKey) => `${PIMS_BASE}/api/v1/incidents/process/${processKey}`,
75
76
  GET_BY_INSTANCE: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/incidents`,
76
77
  },
78
+ TRACES: {
79
+ GET_SPANS: (traceId) => `${LLMOPS_BASE}/api/Traces/spans?traceId=${traceId}`,
80
+ },
77
81
  INSIGHTS: {
78
82
  /** Top processes ranked by run count */
79
83
  TOP_PROCESSES_BY_RUN_COUNT: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/TopProcessesByRunCount`,
80
84
  /** Top processes ranked by failure count */
81
85
  TOP_PROCESSES_WITH_FAILURE: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/TopProcesseswithFailure`,
86
+ /** Top elements ranked by failure count */
87
+ TOP_ELEMENTS_WITH_FAILURE: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/TopElementswithFailure`,
82
88
  /** Instance status aggregated by date for time-series charts */
83
89
  INSTANCE_STATUS_BY_DATE: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/InstanceStatusByDate`,
84
90
  /** Top processes ranked by total duration */
85
91
  TOP_PROCESSES_BY_DURATION: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/TopProcessesByDuration`,
92
+ /** Element count by status for agentic instances (process and case) */
93
+ ELEMENT_COUNT_BY_STATUS: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/ElementCountByStatus`,
86
94
  },
87
95
  };
88
96
 
@@ -105,6 +113,13 @@ function createProcessMethods(processData, service) {
105
113
  if (!processData.folderKey)
106
114
  throw new Error('Folder key is undefined');
107
115
  return service.getIncidents(processData.processKey, processData.folderKey);
116
+ },
117
+ getElementStats(startTime, endTime, packageVersion) {
118
+ if (!processData.processKey)
119
+ throw new Error('Process key is undefined');
120
+ if (!processData.packageId)
121
+ throw new Error('Package ID is undefined');
122
+ return service.getElementStats(processData.processKey, processData.packageId, startTime, endTime, packageVersion);
108
123
  }
109
124
  };
110
125
  }
@@ -166,6 +181,28 @@ async function fetchInstanceStatusTimeline(postFn, startTime, endTime, isCaseMan
166
181
  });
167
182
  return response.data ?? [];
168
183
  }
184
+ /**
185
+ * Builds the request body for the ElementCountByStatus endpoint.
186
+ *
187
+ * @param processKey - Process key to filter by
188
+ * @param packageId - Package identifier
189
+ * @param startTime - Start of the time range to query
190
+ * @param endTime - End of the time range to query
191
+ * @param packageVersion - Package version to filter by
192
+ * @returns Request body for the ElementCountByStatus endpoint
193
+ * @internal
194
+ */
195
+ function buildElementCountByStatusBody(processKey, packageId, startTime, endTime, packageVersion) {
196
+ return {
197
+ commonParams: {
198
+ processKey,
199
+ packageId,
200
+ startTime: startTime.getTime(),
201
+ endTime: endTime.getTime(),
202
+ version: packageVersion
203
+ }
204
+ };
205
+ }
169
206
 
170
207
  /**
171
208
  * Common constants used across the SDK
@@ -1158,6 +1195,32 @@ function filterUndefined(obj) {
1158
1195
  */
1159
1196
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
1160
1197
  isBrowser && window.self != window.top && window.location.href.includes('source=ActionCenter');
1198
+ const _params = isBrowser ? new URLSearchParams(window.location.search) : null;
1199
+ /**
1200
+ * True when the coded app has been loaded inside a host frame that explicitly
1201
+ * opted into token delegation by adding `?host=embed` to the iframe src URL.
1202
+ */
1203
+ const isHostEmbedded = isBrowser && window.self !== window.top && _params?.get('host') === 'embed';
1204
+ /**
1205
+ * The validated parent origin, read from the `?basedomain=` query param set
1206
+ * by the embedding host in the iframe src URL.
1207
+ * Mirrors the same mechanism used by ActionCenterTokenManager.
1208
+ * Non-null only when `?host=embed` is present and `?basedomain=` is a valid URL.
1209
+ */
1210
+ (() => {
1211
+ if (!isHostEmbedded)
1212
+ return null;
1213
+ const basedomain = _params?.get('basedomain');
1214
+ if (!basedomain)
1215
+ return null;
1216
+ try {
1217
+ return new URL(basedomain).origin;
1218
+ }
1219
+ catch {
1220
+ console.warn('embeddingOrigin: basedomain query param is not a valid URL', basedomain);
1221
+ return null;
1222
+ }
1223
+ })();
1161
1224
 
1162
1225
  /**
1163
1226
  * Base64 encoding/decoding
@@ -1484,8 +1547,9 @@ class PaginationHelpers {
1484
1547
  });
1485
1548
  }
1486
1549
  // Extract and transform items from response
1487
- // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N })
1488
- const rawItems = Array.isArray(response.data) ? response.data : response.data?.[itemsField];
1550
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1551
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1552
+ const rawItems = Array.isArray(response.data) ? response.data : resolveNestedField(response.data, itemsField);
1489
1553
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1490
1554
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1491
1555
  // Parse items - automatically handle JSON string responses
@@ -1531,7 +1595,7 @@ class PaginationHelpers {
1531
1595
  getEndpoint: config.getEndpoint,
1532
1596
  folderId,
1533
1597
  headers: config.headers,
1534
- paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1598
+ paginationParams: cursor ? { cursor, pageSize } : jumpToPage !== undefined ? { jumpToPage, pageSize } : { pageSize },
1535
1599
  additionalParams: prefixedOptions,
1536
1600
  transformFn: config.transformFn,
1537
1601
  method: config.method,
@@ -1789,6 +1853,8 @@ class BaseService {
1789
1853
  // When true (default), converts pageNumber to a skip/offset value (e.g., page 3 with pageSize 10 → skip 20).
1790
1854
  // When false, passes pageNumber directly as the offset param — used by APIs that accept a page number instead of a record offset.
1791
1855
  const convertToSkip = paginationParams?.convertToSkip ?? true;
1856
+ // When true, sends pageNumber - 1 (for 0-based APIs). Default false (1-based).
1857
+ const zeroBased = paginationParams?.zeroBased ?? false;
1792
1858
  requestParams[pageSizeParam] = limitedPageSize;
1793
1859
  if (convertToSkip) {
1794
1860
  if (params.pageNumber && params.pageNumber > 1) {
@@ -1796,7 +1862,8 @@ class BaseService {
1796
1862
  }
1797
1863
  }
1798
1864
  else {
1799
- requestParams[offsetParam] = params.pageNumber || 1;
1865
+ const sdkPageNumber = params.pageNumber || 1;
1866
+ requestParams[offsetParam] = zeroBased ? sdkPageNumber - 1 : sdkPageNumber;
1800
1867
  }
1801
1868
  {
1802
1869
  requestParams[countParam] = true;
@@ -1825,8 +1892,9 @@ class BaseService {
1825
1892
  const totalCountField = fields.totalCountField || 'totalRecordCount';
1826
1893
  const continuationTokenField = fields.continuationTokenField || 'continuationToken';
1827
1894
  // Extract items and metadata
1828
- // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N })
1829
- const items = Array.isArray(response.data) ? response.data : (response.data[itemsField] || []);
1895
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1896
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1897
+ const items = Array.isArray(response.data) ? response.data : (resolveNestedField(response.data, itemsField) || []);
1830
1898
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1831
1899
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1832
1900
  const continuationToken = response.data[continuationTokenField];
@@ -1913,7 +1981,9 @@ function createProcessInstanceMethods(instanceData, service) {
1913
1981
  async getExecutionHistory() {
1914
1982
  if (!instanceData.instanceId)
1915
1983
  throw new Error('Process instance ID is undefined');
1916
- return service.getExecutionHistory(instanceData.instanceId);
1984
+ if (!instanceData.folderKey)
1985
+ throw new Error('Process instance folder key is undefined');
1986
+ return service.getExecutionHistory(instanceData.instanceId, instanceData.folderKey);
1917
1987
  },
1918
1988
  async getBpmn() {
1919
1989
  if (!instanceData.instanceId)
@@ -2110,12 +2180,6 @@ const ProcessInstanceMap = {
2110
2180
  createdAt: 'createdTime',
2111
2181
  updatedAt: 'updatedTime'
2112
2182
  };
2113
- /**
2114
- * Maps fields for Process Instance Execution History to ensure consistent naming
2115
- */
2116
- const ProcessInstanceExecutionHistoryMap = {
2117
- startTime: 'startedTime'
2118
- };
2119
2183
 
2120
2184
  class ProcessInstancesService extends BaseService {
2121
2185
  /**
@@ -2196,11 +2260,66 @@ class ProcessInstancesService extends BaseService {
2196
2260
  /**
2197
2261
  * Get execution history (spans) for a process instance
2198
2262
  * @param instanceId The ID of the instance to get history for
2199
- * @returns Promise<ProcessInstanceExecutionHistoryResponse[]>
2263
+ * @param folderKey The folder key for authorization
2264
+ * @returns Promise resolving to execution history
2265
+ * {@link ProcessInstanceExecutionHistoryResponse}
2266
+ * @example
2267
+ * ```typescript
2268
+ * // Get execution history for a process instance
2269
+ * const history = await processInstances.getExecutionHistory(
2270
+ * <instanceId>,
2271
+ * <folderKey>
2272
+ * );
2273
+ *
2274
+ * // Analyze execution timeline
2275
+ * history.forEach(span => {
2276
+ * console.log(`Activity: ${span.name}`);
2277
+ * console.log(`Start: ${span.startedTime}`);
2278
+ * console.log(`End: ${span.endTime}`);
2279
+ * });
2280
+ * ```
2200
2281
  */
2201
- async getExecutionHistory(instanceId) {
2202
- const response = await this.get(MAESTRO_ENDPOINTS.INSTANCES.GET_EXECUTION_HISTORY(instanceId));
2203
- return response.data.map(historyItem => transformData(historyItem, ProcessInstanceExecutionHistoryMap));
2282
+ async getExecutionHistory(instanceId, folderKey) {
2283
+ const headers = createHeaders({ [FOLDER_KEY]: folderKey });
2284
+ const elementExecResponse = await this.get(MAESTRO_ENDPOINTS.INSTANCES.GET_ELEMENT_EXECUTIONS(instanceId), { headers });
2285
+ const traceId = elementExecResponse.data.traceId;
2286
+ const spansResponse = await this.get(MAESTRO_ENDPOINTS.TRACES.GET_SPANS(traceId), { headers });
2287
+ // Build span lookup keyed by elementRunId extracted from Attributes JSON
2288
+ const spanMap = new Map();
2289
+ for (const span of spansResponse.data) {
2290
+ try {
2291
+ const attrs = span.Attributes ? JSON.parse(span.Attributes) : null;
2292
+ if (attrs?.elementRunId) {
2293
+ spanMap.set(attrs.elementRunId, span);
2294
+ }
2295
+ }
2296
+ catch {
2297
+ // skip spans with unparseable Attributes — they won't match any elementRunId
2298
+ }
2299
+ }
2300
+ const results = [];
2301
+ for (const elementExec of elementExecResponse.data.elementExecutions) {
2302
+ for (const run of elementExec.elementRuns) {
2303
+ const span = spanMap.get(run.elementRunId);
2304
+ if (span) {
2305
+ results.push(this.mapSpanToHistory(span));
2306
+ }
2307
+ }
2308
+ }
2309
+ return results;
2310
+ }
2311
+ mapSpanToHistory(span) {
2312
+ return {
2313
+ id: span.Id,
2314
+ traceId: span.TraceId,
2315
+ parentId: span.ParentId,
2316
+ name: span.Name,
2317
+ startedTime: span.StartTime,
2318
+ endTime: span.EndTime,
2319
+ attributes: span.Attributes,
2320
+ updatedTime: span.UpdatedAt,
2321
+ expiredTime: span.ExpiryTimeUtc,
2322
+ };
2204
2323
  }
2205
2324
  /**
2206
2325
  * Get BPMN XML file for a process instance
@@ -2516,6 +2635,52 @@ class MaestroProcessesService extends BaseService {
2516
2635
  const { data } = await this.post(MAESTRO_ENDPOINTS.INSIGHTS.TOP_PROCESSES_BY_RUN_COUNT, buildInsightsTopBody(startTime, endTime, false, options));
2517
2636
  return (data ?? []).map(process => ({ ...process, name: process.packageId }));
2518
2637
  }
2638
+ /**
2639
+ * Get the top 10 BPMN elements ranked by failure count within a time range.
2640
+ *
2641
+ * Returns an array of up to 10 elements sorted by how many times they failed,
2642
+ * useful for identifying the most error-prone activities in processes.
2643
+ *
2644
+ * @param startTime - Start of the time range to query
2645
+ * @param endTime - End of the time range to query
2646
+ * @param options - Optional filters (packageId, processKey, version)
2647
+ * @returns Promise resolving to an array of {@link ElementGetTopFailedCountResponse}
2648
+ * @example
2649
+ * ```typescript
2650
+ * import { MaestroProcesses } from '@uipath/uipath-typescript/maestro-processes';
2651
+ *
2652
+ * const maestroProcesses = new MaestroProcesses(sdk);
2653
+ *
2654
+ * // Get top failing elements for the last 7 days
2655
+ * const topFailing = await maestroProcesses.getTopElementFailedCount(
2656
+ * new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
2657
+ * new Date()
2658
+ * );
2659
+ *
2660
+ * for (const element of topFailing) {
2661
+ * console.log(`${element.elementName} (${element.elementType}): ${element.failedCount} failures`);
2662
+ * }
2663
+ * ```
2664
+ *
2665
+ * @example
2666
+ * ```typescript
2667
+ * // Get top failing elements for a specific process
2668
+ * const filtered = await maestroProcesses.getTopElementFailedCount(
2669
+ * new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
2670
+ * new Date(),
2671
+ * { processKey: '<processKey>' }
2672
+ * );
2673
+ * ```
2674
+ */
2675
+ async getTopElementFailedCount(startTime, endTime, options) {
2676
+ const { data } = await this.post(MAESTRO_ENDPOINTS.INSIGHTS.TOP_ELEMENTS_WITH_FAILURE, buildInsightsTopBody(startTime, endTime, false, options));
2677
+ return (data ?? []).map(item => ({
2678
+ elementName: item.elementName,
2679
+ elementType: item.elementType,
2680
+ processKey: item.processKey,
2681
+ failedCount: item.count,
2682
+ }));
2683
+ }
2519
2684
  /**
2520
2685
  * Get all instances status counts aggregated by date for maestro processes.
2521
2686
  *
@@ -2646,6 +2811,41 @@ class MaestroProcessesService extends BaseService {
2646
2811
  const { data } = await this.post(MAESTRO_ENDPOINTS.INSIGHTS.TOP_PROCESSES_BY_DURATION, buildInsightsTopBody(startTime, endTime, false, options));
2647
2812
  return (data ?? []).map(process => ({ ...process, name: process.packageId }));
2648
2813
  }
2814
+ /**
2815
+ * Get element stats for process instances
2816
+ *
2817
+ * Returns per-element execution counts (success, fail, terminated, paused, in-progress) and
2818
+ * duration percentile metrics (min, max, avg, p50, p95, p99) for BPMN elements within a process.
2819
+ *
2820
+ * @param processKey - Process key to filter by
2821
+ * @param packageId - Package identifier
2822
+ * @param startTime - Start of the time range to query
2823
+ * @param endTime - End of the time range to query
2824
+ * @param packageVersion - Package version to filter by
2825
+ * @returns Promise resolving to an array of {@link ElementStats}
2826
+ * @example
2827
+ * ```typescript
2828
+ * // Get element metrics for a process
2829
+ * const elements = await maestroProcesses.getElementStats(
2830
+ * '<processKey>',
2831
+ * '<packageId>',
2832
+ * new Date('2026-04-01'),
2833
+ * new Date(),
2834
+ * '1.0.1'
2835
+ * );
2836
+ *
2837
+ * // Analyze element performance
2838
+ * for (const element of elements) {
2839
+ * console.log(`Element: ${element.elementId}`);
2840
+ * console.log(` Success: ${element.successCount}, Failed: ${element.failCount}`);
2841
+ * console.log(` Avg duration: ${element.avgDurationMs}ms, P95: ${element.p95DurationMs}ms`);
2842
+ * }
2843
+ * ```
2844
+ */
2845
+ async getElementStats(processKey, packageId, startTime, endTime, packageVersion) {
2846
+ const { data } = await this.post(MAESTRO_ENDPOINTS.INSIGHTS.ELEMENT_COUNT_BY_STATUS, buildElementCountByStatusBody(processKey, packageId, startTime, endTime, packageVersion));
2847
+ return data ?? [];
2848
+ }
2649
2849
  }
2650
2850
  __decorate([
2651
2851
  track('MaestroProcesses.GetAll')
@@ -2656,6 +2856,9 @@ __decorate([
2656
2856
  __decorate([
2657
2857
  track('MaestroProcesses.GetTopRunCount')
2658
2858
  ], MaestroProcessesService.prototype, "getTopRunCount", null);
2859
+ __decorate([
2860
+ track('MaestroProcesses.GetTopElementFailedCount')
2861
+ ], MaestroProcessesService.prototype, "getTopElementFailedCount", null);
2659
2862
  __decorate([
2660
2863
  track('MaestroProcesses.GetInstanceStatusTimeline')
2661
2864
  ], MaestroProcessesService.prototype, "getInstanceStatusTimeline", null);
@@ -2665,6 +2868,9 @@ __decorate([
2665
2868
  __decorate([
2666
2869
  track('MaestroProcesses.GetTopExecutionDuration')
2667
2870
  ], MaestroProcessesService.prototype, "getTopExecutionDuration", null);
2871
+ __decorate([
2872
+ track('MaestroProcesses.GetElementStats')
2873
+ ], MaestroProcessesService.prototype, "getElementStats", null);
2668
2874
 
2669
2875
  /**
2670
2876
  * Service class for Maestro Process Incidents