@uipath/uipath-typescript 1.3.11 → 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 +141 -10
  17. package/dist/cases/index.d.ts +118 -7
  18. package/dist/cases/index.mjs +141 -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 +122 -43
  26. package/dist/entities/index.d.ts +140 -35
  27. package/dist/entities/index.mjs +122 -43
  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 +956 -283
  35. package/dist/index.d.ts +1138 -121
  36. package/dist/index.mjs +956 -284
  37. package/dist/index.umd.js +3113 -2423
  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 +173 -18
  42. package/dist/maestro-processes/index.d.ts +131 -9
  43. package/dist/maestro-processes/index.mjs +173 -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 +37 -6
  54. package/dist/traces/index.d.ts +1 -0
  55. package/dist/traces/index.mjs +37 -6
  56. package/package.json +32 -2
@@ -109,6 +109,35 @@ interface GetTopDurationResponse extends GetTopBaseResponse {
109
109
  /** Total execution duration in milliseconds */
110
110
  duration: number;
111
111
  }
112
+ /**
113
+ * Element count by status for a BPMN element within a process or case
114
+ */
115
+ interface ElementStats {
116
+ /** BPMN element identifier */
117
+ elementId: string;
118
+ /** Number of successful executions */
119
+ successCount: number;
120
+ /** Number of failed executions */
121
+ failCount: number;
122
+ /** Number of terminated executions */
123
+ terminatedCount: number;
124
+ /** Number of paused executions */
125
+ pausedCount: number;
126
+ /** Number of in-progress executions */
127
+ inProgressCount: number;
128
+ /** Minimum duration in milliseconds */
129
+ minDurationMs: number;
130
+ /** Maximum duration in milliseconds */
131
+ maxDurationMs: number;
132
+ /** Average duration in milliseconds */
133
+ avgDurationMs: number;
134
+ /** 50th percentile (median) duration in milliseconds */
135
+ p50DurationMs: number;
136
+ /** 95th percentile duration in milliseconds */
137
+ p95DurationMs: number;
138
+ /** 99th percentile duration in milliseconds */
139
+ p99DurationMs: number;
140
+ }
112
141
 
113
142
  /**
114
143
  * Maestro Process Types
@@ -495,6 +524,38 @@ interface MaestroProcessesServiceModel {
495
524
  * ```
496
525
  */
497
526
  getTopExecutionDuration(startTime: Date, endTime: Date, options?: TopQueryOptions): Promise<ProcessGetTopDurationResponse[]>;
527
+ /**
528
+ * Get element stats for process instances
529
+ *
530
+ * Returns per-element execution counts (success, fail, terminated, paused, in-progress) and
531
+ * duration percentile metrics (min, max, avg, p50, p95, p99) for BPMN elements within a process.
532
+ *
533
+ * @param processKey - Process key to filter by
534
+ * @param packageId - Package identifier
535
+ * @param startTime - Start of the time range to query
536
+ * @param endTime - End of the time range to query
537
+ * @param packageVersion - Package version to filter by
538
+ * @returns Promise resolving to an array of {@link ElementStats}
539
+ * @example
540
+ * ```typescript
541
+ * // Get element metrics for a process
542
+ * const elements = await maestroProcesses.getElementStats(
543
+ * '<processKey>',
544
+ * '<packageId>',
545
+ * new Date('2026-04-01'),
546
+ * new Date(),
547
+ * '1.0.1'
548
+ * );
549
+ *
550
+ * // Analyze element performance
551
+ * for (const element of elements) {
552
+ * console.log(`Element: ${element.elementId}`);
553
+ * console.log(` Success: ${element.successCount}, Failed: ${element.failCount}`);
554
+ * console.log(` Avg duration: ${element.avgDurationMs}ms, P95: ${element.p95DurationMs}ms`);
555
+ * }
556
+ * ```
557
+ */
558
+ getElementStats(processKey: string, packageId: string, startTime: Date, endTime: Date, packageVersion: string): Promise<ElementStats[]>;
498
559
  }
499
560
  interface ProcessMethods {
500
561
  /**
@@ -503,6 +564,15 @@ interface ProcessMethods {
503
564
  * @returns Promise resolving to array of process incidents
504
565
  */
505
566
  getIncidents(): Promise<ProcessIncidentGetResponse[]>;
567
+ /**
568
+ * Get element stats for this process
569
+ *
570
+ * @param startTime - Start of the time range to query
571
+ * @param endTime - End of the time range to query
572
+ * @param packageVersion - Package version to filter by
573
+ * @returns Promise resolving to an array of {@link ElementStats}
574
+ */
575
+ getElementStats(startTime: Date, endTime: Date, packageVersion: string): Promise<ElementStats[]>;
506
576
  }
507
577
  type MaestroProcessGetAllResponse = RawMaestroProcessGetAllResponse & ProcessMethods;
508
578
  /**
@@ -645,8 +715,7 @@ interface ProcessInstanceExecutionHistoryResponse {
645
715
  startedTime: string;
646
716
  endTime: string | null;
647
717
  attributes: string | null;
648
- createdTime: string;
649
- updatedTime?: string;
718
+ updatedTime: string;
650
719
  expiredTime: string | null;
651
720
  }
652
721
  /**
@@ -793,24 +862,26 @@ interface ProcessInstancesServiceModel {
793
862
  /**
794
863
  * Get execution history (spans) for a process instance
795
864
  * @param instanceId The ID of the instance to get history for
865
+ * @param folderKey The folder key for authorization
796
866
  * @returns Promise resolving to execution history
797
867
  * {@link ProcessInstanceExecutionHistoryResponse}
798
868
  * @example
799
869
  * ```typescript
800
870
  * // Get execution history for a process instance
801
871
  * const history = await processInstances.getExecutionHistory(
802
- * <instanceId>
872
+ * <instanceId>,
873
+ * <folderKey>
803
874
  * );
804
875
  *
805
876
  * // Analyze execution timeline
806
877
  * history.forEach(span => {
807
878
  * console.log(`Activity: ${span.name}`);
808
- * console.log(`Start: ${span.startTime}`);
809
- * console.log(`Duration: ${span.duration}ms`);
879
+ * console.log(`Start: ${span.startedTime}`);
880
+ * console.log(`End: ${span.endTime}`);
810
881
  * });
811
882
  * ```
812
883
  */
813
- getExecutionHistory(instanceId: string): Promise<ProcessInstanceExecutionHistoryResponse[]>;
884
+ getExecutionHistory(instanceId: string, folderKey: string): Promise<ProcessInstanceExecutionHistoryResponse[]>;
814
885
  /**
815
886
  * Get BPMN XML file for a process instance
816
887
  * @param instanceId The ID of the instance to get BPMN for
@@ -1076,6 +1147,7 @@ interface RequestWithPaginationOptions extends RequestSpec {
1076
1147
  tokenParam?: string;
1077
1148
  countParam?: string;
1078
1149
  convertToSkip?: boolean;
1150
+ zeroBased?: boolean;
1079
1151
  };
1080
1152
  };
1081
1153
  }
@@ -1496,6 +1568,38 @@ declare class MaestroProcessesService extends BaseService implements MaestroProc
1496
1568
  * ```
1497
1569
  */
1498
1570
  getTopExecutionDuration(startTime: Date, endTime: Date, options?: TopQueryOptions): Promise<ProcessGetTopDurationResponse[]>;
1571
+ /**
1572
+ * Get element stats for process instances
1573
+ *
1574
+ * Returns per-element execution counts (success, fail, terminated, paused, in-progress) and
1575
+ * duration percentile metrics (min, max, avg, p50, p95, p99) for BPMN elements within a process.
1576
+ *
1577
+ * @param processKey - Process key to filter by
1578
+ * @param packageId - Package identifier
1579
+ * @param startTime - Start of the time range to query
1580
+ * @param endTime - End of the time range to query
1581
+ * @param packageVersion - Package version to filter by
1582
+ * @returns Promise resolving to an array of {@link ElementStats}
1583
+ * @example
1584
+ * ```typescript
1585
+ * // Get element metrics for a process
1586
+ * const elements = await maestroProcesses.getElementStats(
1587
+ * '<processKey>',
1588
+ * '<packageId>',
1589
+ * new Date('2026-04-01'),
1590
+ * new Date(),
1591
+ * '1.0.1'
1592
+ * );
1593
+ *
1594
+ * // Analyze element performance
1595
+ * for (const element of elements) {
1596
+ * console.log(`Element: ${element.elementId}`);
1597
+ * console.log(` Success: ${element.successCount}, Failed: ${element.failCount}`);
1598
+ * console.log(` Avg duration: ${element.avgDurationMs}ms, P95: ${element.p95DurationMs}ms`);
1599
+ * }
1600
+ * ```
1601
+ */
1602
+ getElementStats(processKey: string, packageId: string, startTime: Date, endTime: Date, packageVersion: string): Promise<ElementStats[]>;
1499
1603
  }
1500
1604
 
1501
1605
  declare class ProcessInstancesService extends BaseService implements ProcessInstancesServiceModel {
@@ -1550,9 +1654,27 @@ declare class ProcessInstancesService extends BaseService implements ProcessInst
1550
1654
  /**
1551
1655
  * Get execution history (spans) for a process instance
1552
1656
  * @param instanceId The ID of the instance to get history for
1553
- * @returns Promise<ProcessInstanceExecutionHistoryResponse[]>
1657
+ * @param folderKey The folder key for authorization
1658
+ * @returns Promise resolving to execution history
1659
+ * {@link ProcessInstanceExecutionHistoryResponse}
1660
+ * @example
1661
+ * ```typescript
1662
+ * // Get execution history for a process instance
1663
+ * const history = await processInstances.getExecutionHistory(
1664
+ * <instanceId>,
1665
+ * <folderKey>
1666
+ * );
1667
+ *
1668
+ * // Analyze execution timeline
1669
+ * history.forEach(span => {
1670
+ * console.log(`Activity: ${span.name}`);
1671
+ * console.log(`Start: ${span.startedTime}`);
1672
+ * console.log(`End: ${span.endTime}`);
1673
+ * });
1674
+ * ```
1554
1675
  */
1555
- getExecutionHistory(instanceId: string): Promise<ProcessInstanceExecutionHistoryResponse[]>;
1676
+ getExecutionHistory(instanceId: string, folderKey: string): Promise<ProcessInstanceExecutionHistoryResponse[]>;
1677
+ private mapSpanToHistory;
1556
1678
  /**
1557
1679
  * Get BPMN XML file for a process instance
1558
1680
  * @param instanceId The ID of the instance to get BPMN for
@@ -1652,4 +1774,4 @@ declare class ProcessIncidentsService extends BaseService implements ProcessInci
1652
1774
  }
1653
1775
 
1654
1776
  export { DebugMode, InstanceFinalStatus, MaestroProcessesService as MaestroProcesses, MaestroProcessesService, ProcessIncidentSeverity, ProcessIncidentStatus, ProcessIncidentType, ProcessIncidentsService as ProcessIncidents, ProcessIncidentsService, ProcessInstancesService as ProcessInstances, ProcessInstancesService, TimeInterval, createProcessInstanceWithMethods, createProcessWithMethods };
1655
- export type { BpmnXmlString, ElementGetTopFailedCountResponse, ElementMetaData, GetTopBaseResponse, GetTopDurationResponse, GetTopFaultedCountResponse, GetTopRunCountResponse, GlobalVariableMetaData, InstanceStatusTimelineResponse, MaestroProcessGetAllResponse, MaestroProcessesServiceModel, ProcessGetTopDurationResponse, ProcessGetTopFaultedCountResponse, ProcessGetTopRunCountResponse, ProcessIncidentGetAllResponse, ProcessIncidentGetResponse, ProcessIncidentsServiceModel, ProcessInstanceExecutionHistoryResponse, ProcessInstanceGetAllOptions, ProcessInstanceGetAllWithPaginationOptions, ProcessInstanceGetResponse, ProcessInstanceGetVariablesOptions, ProcessInstanceGetVariablesResponse, ProcessInstanceMethods, ProcessInstanceOperationOptions, ProcessInstanceOperationResponse, ProcessInstanceRun, ProcessInstancesServiceModel, ProcessMethods, RawMaestroProcessGetAllResponse, RawProcessInstanceGetResponse, TimelineOptions, TopQueryOptions };
1777
+ export type { BpmnXmlString, ElementGetTopFailedCountResponse, ElementMetaData, ElementStats, GetTopBaseResponse, GetTopDurationResponse, GetTopFaultedCountResponse, GetTopRunCountResponse, GlobalVariableMetaData, InstanceStatusTimelineResponse, MaestroProcessGetAllResponse, MaestroProcessesServiceModel, ProcessGetTopDurationResponse, ProcessGetTopFaultedCountResponse, ProcessGetTopRunCountResponse, ProcessIncidentGetAllResponse, ProcessIncidentGetResponse, ProcessIncidentsServiceModel, ProcessInstanceExecutionHistoryResponse, ProcessInstanceGetAllOptions, ProcessInstanceGetAllWithPaginationOptions, ProcessInstanceGetResponse, ProcessInstanceGetVariablesOptions, ProcessInstanceGetVariablesResponse, ProcessInstanceMethods, ProcessInstanceOperationOptions, ProcessInstanceOperationResponse, ProcessInstanceRun, ProcessInstancesServiceModel, ProcessMethods, RawMaestroProcessGetAllResponse, RawProcessInstanceGetResponse, TimelineOptions, TopQueryOptions };
@@ -46,6 +46,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
46
46
  * Base path constants for different services
47
47
  */
48
48
  const PIMS_BASE = 'pims_';
49
+ const LLMOPS_BASE = 'llmopstenant_';
49
50
  const INSIGHTS_RTM_BASE = 'insightsrtm_';
50
51
 
51
52
  /**
@@ -60,7 +61,7 @@ const MAESTRO_ENDPOINTS = {
60
61
  INSTANCES: {
61
62
  GET_ALL: `${PIMS_BASE}/api/v1/instances`,
62
63
  GET_BY_ID: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}`,
63
- GET_EXECUTION_HISTORY: (instanceId) => `${PIMS_BASE}/api/v1/spans/${instanceId}`,
64
+ GET_ELEMENT_EXECUTIONS: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/element-executions`,
64
65
  GET_BPMN: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/bpmn`,
65
66
  GET_VARIABLES: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/variables`,
66
67
  CANCEL: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/cancel`,
@@ -72,6 +73,9 @@ const MAESTRO_ENDPOINTS = {
72
73
  GET_BY_PROCESS: (processKey) => `${PIMS_BASE}/api/v1/incidents/process/${processKey}`,
73
74
  GET_BY_INSTANCE: (instanceId) => `${PIMS_BASE}/api/v1/instances/${instanceId}/incidents`,
74
75
  },
76
+ TRACES: {
77
+ GET_SPANS: (traceId) => `${LLMOPS_BASE}/api/Traces/spans?traceId=${traceId}`,
78
+ },
75
79
  INSIGHTS: {
76
80
  /** Top processes ranked by run count */
77
81
  TOP_PROCESSES_BY_RUN_COUNT: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/TopProcessesByRunCount`,
@@ -83,6 +87,8 @@ const MAESTRO_ENDPOINTS = {
83
87
  INSTANCE_STATUS_BY_DATE: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/InstanceStatusByDate`,
84
88
  /** Top processes ranked by total duration */
85
89
  TOP_PROCESSES_BY_DURATION: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/TopProcessesByDuration`,
90
+ /** Element count by status for agentic instances (process and case) */
91
+ ELEMENT_COUNT_BY_STATUS: `${INSIGHTS_RTM_BASE}/agenticInstanceStatus/ElementCountByStatus`,
86
92
  },
87
93
  };
88
94
 
@@ -105,6 +111,13 @@ function createProcessMethods(processData, service) {
105
111
  if (!processData.folderKey)
106
112
  throw new Error('Folder key is undefined');
107
113
  return service.getIncidents(processData.processKey, processData.folderKey);
114
+ },
115
+ getElementStats(startTime, endTime, packageVersion) {
116
+ if (!processData.processKey)
117
+ throw new Error('Process key is undefined');
118
+ if (!processData.packageId)
119
+ throw new Error('Package ID is undefined');
120
+ return service.getElementStats(processData.processKey, processData.packageId, startTime, endTime, packageVersion);
108
121
  }
109
122
  };
110
123
  }
@@ -166,6 +179,28 @@ async function fetchInstanceStatusTimeline(postFn, startTime, endTime, isCaseMan
166
179
  });
167
180
  return response.data ?? [];
168
181
  }
182
+ /**
183
+ * Builds the request body for the ElementCountByStatus endpoint.
184
+ *
185
+ * @param processKey - Process key to filter by
186
+ * @param packageId - Package identifier
187
+ * @param startTime - Start of the time range to query
188
+ * @param endTime - End of the time range to query
189
+ * @param packageVersion - Package version to filter by
190
+ * @returns Request body for the ElementCountByStatus endpoint
191
+ * @internal
192
+ */
193
+ function buildElementCountByStatusBody(processKey, packageId, startTime, endTime, packageVersion) {
194
+ return {
195
+ commonParams: {
196
+ processKey,
197
+ packageId,
198
+ startTime: startTime.getTime(),
199
+ endTime: endTime.getTime(),
200
+ version: packageVersion
201
+ }
202
+ };
203
+ }
169
204
 
170
205
  /**
171
206
  * Common constants used across the SDK
@@ -1158,6 +1193,32 @@ function filterUndefined(obj) {
1158
1193
  */
1159
1194
  const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
1160
1195
  isBrowser && window.self != window.top && window.location.href.includes('source=ActionCenter');
1196
+ const _params = isBrowser ? new URLSearchParams(window.location.search) : null;
1197
+ /**
1198
+ * True when the coded app has been loaded inside a host frame that explicitly
1199
+ * opted into token delegation by adding `?host=embed` to the iframe src URL.
1200
+ */
1201
+ const isHostEmbedded = isBrowser && window.self !== window.top && _params?.get('host') === 'embed';
1202
+ /**
1203
+ * The validated parent origin, read from the `?basedomain=` query param set
1204
+ * by the embedding host in the iframe src URL.
1205
+ * Mirrors the same mechanism used by ActionCenterTokenManager.
1206
+ * Non-null only when `?host=embed` is present and `?basedomain=` is a valid URL.
1207
+ */
1208
+ (() => {
1209
+ if (!isHostEmbedded)
1210
+ return null;
1211
+ const basedomain = _params?.get('basedomain');
1212
+ if (!basedomain)
1213
+ return null;
1214
+ try {
1215
+ return new URL(basedomain).origin;
1216
+ }
1217
+ catch {
1218
+ console.warn('embeddingOrigin: basedomain query param is not a valid URL', basedomain);
1219
+ return null;
1220
+ }
1221
+ })();
1161
1222
 
1162
1223
  /**
1163
1224
  * Base64 encoding/decoding
@@ -1484,8 +1545,9 @@ class PaginationHelpers {
1484
1545
  });
1485
1546
  }
1486
1547
  // 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];
1548
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1549
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1550
+ const rawItems = Array.isArray(response.data) ? response.data : resolveNestedField(response.data, itemsField);
1489
1551
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1490
1552
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1491
1553
  // Parse items - automatically handle JSON string responses
@@ -1531,7 +1593,7 @@ class PaginationHelpers {
1531
1593
  getEndpoint: config.getEndpoint,
1532
1594
  folderId,
1533
1595
  headers: config.headers,
1534
- paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1596
+ paginationParams: cursor ? { cursor, pageSize } : jumpToPage !== undefined ? { jumpToPage, pageSize } : { pageSize },
1535
1597
  additionalParams: prefixedOptions,
1536
1598
  transformFn: config.transformFn,
1537
1599
  method: config.method,
@@ -1789,6 +1851,8 @@ class BaseService {
1789
1851
  // When true (default), converts pageNumber to a skip/offset value (e.g., page 3 with pageSize 10 → skip 20).
1790
1852
  // When false, passes pageNumber directly as the offset param — used by APIs that accept a page number instead of a record offset.
1791
1853
  const convertToSkip = paginationParams?.convertToSkip ?? true;
1854
+ // When true, sends pageNumber - 1 (for 0-based APIs). Default false (1-based).
1855
+ const zeroBased = paginationParams?.zeroBased ?? false;
1792
1856
  requestParams[pageSizeParam] = limitedPageSize;
1793
1857
  if (convertToSkip) {
1794
1858
  if (params.pageNumber && params.pageNumber > 1) {
@@ -1796,7 +1860,8 @@ class BaseService {
1796
1860
  }
1797
1861
  }
1798
1862
  else {
1799
- requestParams[offsetParam] = params.pageNumber || 1;
1863
+ const sdkPageNumber = params.pageNumber || 1;
1864
+ requestParams[offsetParam] = zeroBased ? sdkPageNumber - 1 : sdkPageNumber;
1800
1865
  }
1801
1866
  {
1802
1867
  requestParams[countParam] = true;
@@ -1825,8 +1890,9 @@ class BaseService {
1825
1890
  const totalCountField = fields.totalCountField || 'totalRecordCount';
1826
1891
  const continuationTokenField = fields.continuationTokenField || 'continuationToken';
1827
1892
  // 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] || []);
1893
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1894
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1895
+ const items = Array.isArray(response.data) ? response.data : (resolveNestedField(response.data, itemsField) || []);
1830
1896
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1831
1897
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1832
1898
  const continuationToken = response.data[continuationTokenField];
@@ -1913,7 +1979,9 @@ function createProcessInstanceMethods(instanceData, service) {
1913
1979
  async getExecutionHistory() {
1914
1980
  if (!instanceData.instanceId)
1915
1981
  throw new Error('Process instance ID is undefined');
1916
- return service.getExecutionHistory(instanceData.instanceId);
1982
+ if (!instanceData.folderKey)
1983
+ throw new Error('Process instance folder key is undefined');
1984
+ return service.getExecutionHistory(instanceData.instanceId, instanceData.folderKey);
1917
1985
  },
1918
1986
  async getBpmn() {
1919
1987
  if (!instanceData.instanceId)
@@ -2110,12 +2178,6 @@ const ProcessInstanceMap = {
2110
2178
  createdAt: 'createdTime',
2111
2179
  updatedAt: 'updatedTime'
2112
2180
  };
2113
- /**
2114
- * Maps fields for Process Instance Execution History to ensure consistent naming
2115
- */
2116
- const ProcessInstanceExecutionHistoryMap = {
2117
- startTime: 'startedTime'
2118
- };
2119
2181
 
2120
2182
  class ProcessInstancesService extends BaseService {
2121
2183
  /**
@@ -2196,11 +2258,66 @@ class ProcessInstancesService extends BaseService {
2196
2258
  /**
2197
2259
  * Get execution history (spans) for a process instance
2198
2260
  * @param instanceId The ID of the instance to get history for
2199
- * @returns Promise<ProcessInstanceExecutionHistoryResponse[]>
2261
+ * @param folderKey The folder key for authorization
2262
+ * @returns Promise resolving to execution history
2263
+ * {@link ProcessInstanceExecutionHistoryResponse}
2264
+ * @example
2265
+ * ```typescript
2266
+ * // Get execution history for a process instance
2267
+ * const history = await processInstances.getExecutionHistory(
2268
+ * <instanceId>,
2269
+ * <folderKey>
2270
+ * );
2271
+ *
2272
+ * // Analyze execution timeline
2273
+ * history.forEach(span => {
2274
+ * console.log(`Activity: ${span.name}`);
2275
+ * console.log(`Start: ${span.startedTime}`);
2276
+ * console.log(`End: ${span.endTime}`);
2277
+ * });
2278
+ * ```
2200
2279
  */
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));
2280
+ async getExecutionHistory(instanceId, folderKey) {
2281
+ const headers = createHeaders({ [FOLDER_KEY]: folderKey });
2282
+ const elementExecResponse = await this.get(MAESTRO_ENDPOINTS.INSTANCES.GET_ELEMENT_EXECUTIONS(instanceId), { headers });
2283
+ const traceId = elementExecResponse.data.traceId;
2284
+ const spansResponse = await this.get(MAESTRO_ENDPOINTS.TRACES.GET_SPANS(traceId), { headers });
2285
+ // Build span lookup keyed by elementRunId extracted from Attributes JSON
2286
+ const spanMap = new Map();
2287
+ for (const span of spansResponse.data) {
2288
+ try {
2289
+ const attrs = span.Attributes ? JSON.parse(span.Attributes) : null;
2290
+ if (attrs?.elementRunId) {
2291
+ spanMap.set(attrs.elementRunId, span);
2292
+ }
2293
+ }
2294
+ catch {
2295
+ // skip spans with unparseable Attributes — they won't match any elementRunId
2296
+ }
2297
+ }
2298
+ const results = [];
2299
+ for (const elementExec of elementExecResponse.data.elementExecutions) {
2300
+ for (const run of elementExec.elementRuns) {
2301
+ const span = spanMap.get(run.elementRunId);
2302
+ if (span) {
2303
+ results.push(this.mapSpanToHistory(span));
2304
+ }
2305
+ }
2306
+ }
2307
+ return results;
2308
+ }
2309
+ mapSpanToHistory(span) {
2310
+ return {
2311
+ id: span.Id,
2312
+ traceId: span.TraceId,
2313
+ parentId: span.ParentId,
2314
+ name: span.Name,
2315
+ startedTime: span.StartTime,
2316
+ endTime: span.EndTime,
2317
+ attributes: span.Attributes,
2318
+ updatedTime: span.UpdatedAt,
2319
+ expiredTime: span.ExpiryTimeUtc,
2320
+ };
2204
2321
  }
2205
2322
  /**
2206
2323
  * Get BPMN XML file for a process instance
@@ -2692,6 +2809,41 @@ class MaestroProcessesService extends BaseService {
2692
2809
  const { data } = await this.post(MAESTRO_ENDPOINTS.INSIGHTS.TOP_PROCESSES_BY_DURATION, buildInsightsTopBody(startTime, endTime, false, options));
2693
2810
  return (data ?? []).map(process => ({ ...process, name: process.packageId }));
2694
2811
  }
2812
+ /**
2813
+ * Get element stats for process instances
2814
+ *
2815
+ * Returns per-element execution counts (success, fail, terminated, paused, in-progress) and
2816
+ * duration percentile metrics (min, max, avg, p50, p95, p99) for BPMN elements within a process.
2817
+ *
2818
+ * @param processKey - Process key to filter by
2819
+ * @param packageId - Package identifier
2820
+ * @param startTime - Start of the time range to query
2821
+ * @param endTime - End of the time range to query
2822
+ * @param packageVersion - Package version to filter by
2823
+ * @returns Promise resolving to an array of {@link ElementStats}
2824
+ * @example
2825
+ * ```typescript
2826
+ * // Get element metrics for a process
2827
+ * const elements = await maestroProcesses.getElementStats(
2828
+ * '<processKey>',
2829
+ * '<packageId>',
2830
+ * new Date('2026-04-01'),
2831
+ * new Date(),
2832
+ * '1.0.1'
2833
+ * );
2834
+ *
2835
+ * // Analyze element performance
2836
+ * for (const element of elements) {
2837
+ * console.log(`Element: ${element.elementId}`);
2838
+ * console.log(` Success: ${element.successCount}, Failed: ${element.failCount}`);
2839
+ * console.log(` Avg duration: ${element.avgDurationMs}ms, P95: ${element.p95DurationMs}ms`);
2840
+ * }
2841
+ * ```
2842
+ */
2843
+ async getElementStats(processKey, packageId, startTime, endTime, packageVersion) {
2844
+ const { data } = await this.post(MAESTRO_ENDPOINTS.INSIGHTS.ELEMENT_COUNT_BY_STATUS, buildElementCountByStatusBody(processKey, packageId, startTime, endTime, packageVersion));
2845
+ return data ?? [];
2846
+ }
2695
2847
  }
2696
2848
  __decorate([
2697
2849
  track('MaestroProcesses.GetAll')
@@ -2714,6 +2866,9 @@ __decorate([
2714
2866
  __decorate([
2715
2867
  track('MaestroProcesses.GetTopExecutionDuration')
2716
2868
  ], MaestroProcessesService.prototype, "getTopExecutionDuration", null);
2869
+ __decorate([
2870
+ track('MaestroProcesses.GetElementStats')
2871
+ ], MaestroProcessesService.prototype, "getElementStats", null);
2717
2872
 
2718
2873
  /**
2719
2874
  * Service class for Maestro Process Incidents
@@ -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
@@ -1344,8 +1370,9 @@ class PaginationHelpers {
1344
1370
  });
1345
1371
  }
1346
1372
  // Extract and transform items from response
1347
- // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N })
1348
- const rawItems = Array.isArray(response.data) ? response.data : response.data?.[itemsField];
1373
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1374
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1375
+ const rawItems = Array.isArray(response.data) ? response.data : resolveNestedField(response.data, itemsField);
1349
1376
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1350
1377
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1351
1378
  // Parse items - automatically handle JSON string responses
@@ -1391,7 +1418,7 @@ class PaginationHelpers {
1391
1418
  getEndpoint: config.getEndpoint,
1392
1419
  folderId,
1393
1420
  headers: config.headers,
1394
- paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1421
+ paginationParams: cursor ? { cursor, pageSize } : jumpToPage !== undefined ? { jumpToPage, pageSize } : { pageSize },
1395
1422
  additionalParams: prefixedOptions,
1396
1423
  transformFn: config.transformFn,
1397
1424
  method: config.method,
@@ -1649,6 +1676,8 @@ class BaseService {
1649
1676
  // When true (default), converts pageNumber to a skip/offset value (e.g., page 3 with pageSize 10 → skip 20).
1650
1677
  // When false, passes pageNumber directly as the offset param — used by APIs that accept a page number instead of a record offset.
1651
1678
  const convertToSkip = paginationParams?.convertToSkip ?? true;
1679
+ // When true, sends pageNumber - 1 (for 0-based APIs). Default false (1-based).
1680
+ const zeroBased = paginationParams?.zeroBased ?? false;
1652
1681
  requestParams[pageSizeParam] = limitedPageSize;
1653
1682
  if (convertToSkip) {
1654
1683
  if (params.pageNumber && params.pageNumber > 1) {
@@ -1656,7 +1685,8 @@ class BaseService {
1656
1685
  }
1657
1686
  }
1658
1687
  else {
1659
- requestParams[offsetParam] = params.pageNumber || 1;
1688
+ const sdkPageNumber = params.pageNumber || 1;
1689
+ requestParams[offsetParam] = zeroBased ? sdkPageNumber - 1 : sdkPageNumber;
1660
1690
  }
1661
1691
  {
1662
1692
  requestParams[countParam] = true;
@@ -1685,8 +1715,9 @@ class BaseService {
1685
1715
  const totalCountField = fields.totalCountField || 'totalRecordCount';
1686
1716
  const continuationTokenField = fields.continuationTokenField || 'continuationToken';
1687
1717
  // Extract items and metadata
1688
- // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N })
1689
- const items = Array.isArray(response.data) ? response.data : (response.data[itemsField] || []);
1718
+ // Handle both plain array responses and envelope responses ({ value: [...], totalRecordCount: N }).
1719
+ // itemsField may be a dotted path (e.g. 'data.agents') for nested envelopes.
1720
+ const items = Array.isArray(response.data) ? response.data : (resolveNestedField(response.data, itemsField) || []);
1690
1721
  const rawTotalCount = Array.isArray(response.data) ? undefined : resolveNestedField(response.data, totalCountField);
1691
1722
  const totalCount = typeof rawTotalCount === 'number' ? rawTotalCount : undefined;
1692
1723
  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
  }