@uipath/codedagent-tool 1.198.0-preview.95 → 1.198.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 (3) hide show
  1. package/dist/init.js +256 -149
  2. package/dist/tool.js +257 -150
  3. package/package.json +2 -2
package/dist/init.js CHANGED
@@ -27089,11 +27089,36 @@ class NodeContextStorage {
27089
27089
  return this.storage.getStore();
27090
27090
  }
27091
27091
  }
27092
+ // ../common/src/telemetry/trace-context.ts
27093
+ var TELEMETRY_TRACEPARENT_ENV = "TRACEPARENT";
27094
+ var TRACEPARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
27095
+ function getProcessEnv() {
27096
+ return globalThis.process?.env;
27097
+ }
27098
+ function parseInboundTraceparent(value) {
27099
+ if (!value) {
27100
+ return;
27101
+ }
27102
+ const match = TRACEPARENT_PATTERN.exec(value.trim().toLowerCase());
27103
+ if (!match) {
27104
+ return;
27105
+ }
27106
+ const [, traceId, parentSpanId] = match;
27107
+ if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId)) {
27108
+ return;
27109
+ }
27110
+ return { traceId, parentSpanId };
27111
+ }
27112
+ function getInboundTraceContext() {
27113
+ return parseInboundTraceparent(getProcessEnv()?.[TELEMETRY_TRACEPARENT_ENV]);
27114
+ }
27115
+
27092
27116
  // ../common/src/telemetry/session-id.ts
27093
27117
  var TELEMETRY_SESSION_ID_ENV = "UIPATH_SESSION_ID";
27094
27118
  var TELEMETRY_SESSION_ID_PROPERTY = "session_id";
27095
27119
  var telemetrySessionIdSlot = singleton("TelemetrySessionId");
27096
- function getProcessEnv() {
27120
+ var telemetryOperationIdSlot = singleton("TelemetryOperationId");
27121
+ function getProcessEnv2() {
27097
27122
  return globalThis.process?.env;
27098
27123
  }
27099
27124
  function normalizeSessionId(value) {
@@ -27104,18 +27129,165 @@ function normalizeSessionId(value) {
27104
27129
  return trimmed || undefined;
27105
27130
  }
27106
27131
  function getConfiguredTelemetrySessionId() {
27107
- return normalizeSessionId(getProcessEnv()?.[TELEMETRY_SESSION_ID_ENV]);
27132
+ return normalizeSessionId(getProcessEnv2()?.[TELEMETRY_SESSION_ID_ENV]);
27108
27133
  }
27109
27134
  function resolveTelemetrySessionId(existingSessionId) {
27110
27135
  return getConfiguredTelemetrySessionId() ?? normalizeSessionId(existingSessionId);
27111
27136
  }
27137
+ function getTelemetryOperationId() {
27138
+ const existing = telemetryOperationIdSlot.get();
27139
+ if (existing) {
27140
+ return existing;
27141
+ }
27142
+ const inboundTraceId = getInboundTraceContext()?.traceId;
27143
+ const generated = inboundTraceId ?? crypto.randomUUID().replaceAll("-", "");
27144
+ telemetryOperationIdSlot.set(generated);
27145
+ return generated;
27146
+ }
27112
27147
  // ../common/src/telemetry/global-telemetry-properties.ts
27113
27148
  var telemetryPropsSlot = singleton("TelemetryDefaultProps");
27114
27149
  function getGlobalTelemetryProperties() {
27115
27150
  return telemetryPropsSlot.get();
27116
27151
  }
27117
27152
 
27153
+ // ../common/src/telemetry/pii-redactor.ts
27154
+ var REDACTED = "[REDACTED]";
27155
+ var MAX_VALUE_LENGTH = 200;
27156
+ var SENSITIVE_NAME_TOKENS = new Set([
27157
+ "token",
27158
+ "tokens",
27159
+ "secret",
27160
+ "secrets",
27161
+ "password",
27162
+ "passwords",
27163
+ "pwd",
27164
+ "credential",
27165
+ "credentials",
27166
+ "auth",
27167
+ "authentication",
27168
+ "authorization",
27169
+ "authority",
27170
+ "cert",
27171
+ "certificate",
27172
+ "certificates"
27173
+ ]);
27174
+ var SENSITIVE_KEY_PREFIXES = new Set([
27175
+ "api",
27176
+ "access",
27177
+ "client",
27178
+ "private",
27179
+ "public",
27180
+ "signing",
27181
+ "encryption",
27182
+ "session",
27183
+ "master",
27184
+ "shared",
27185
+ "root",
27186
+ "ssh",
27187
+ "rsa",
27188
+ "aes",
27189
+ "hmac",
27190
+ "oauth"
27191
+ ]);
27192
+ var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
27193
+ var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
27194
+ var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
27195
+ var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
27196
+ var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
27197
+ var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
27198
+ var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
27199
+ function shortHash(input) {
27200
+ let hash = 2166136261;
27201
+ for (let i = 0;i < input.length; i++) {
27202
+ hash ^= input.charCodeAt(i);
27203
+ hash = Math.imul(hash, 16777619);
27204
+ }
27205
+ return (hash >>> 0).toString(16).padStart(8, "0");
27206
+ }
27207
+ function redactUrl(raw) {
27208
+ try {
27209
+ const url = new URL(raw);
27210
+ return `${url.protocol}//${url.host}`;
27211
+ } catch {
27212
+ return `url#${shortHash(raw)}`;
27213
+ }
27214
+ }
27215
+ function redactValueDetectors(value) {
27216
+ let out = value;
27217
+ out = out.replace(JWT_PATTERN, () => REDACTED);
27218
+ out = out.replace(URL_PATTERN, (match) => {
27219
+ const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
27220
+ const core2 = trailing ? match.slice(0, -trailing.length) : match;
27221
+ return `${redactUrl(core2)}${trailing}`;
27222
+ });
27223
+ out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
27224
+ out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
27225
+ out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
27226
+ out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
27227
+ if (out.length > MAX_VALUE_LENGTH) {
27228
+ out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
27229
+ }
27230
+ return out;
27231
+ }
27232
+ function redactValue(value) {
27233
+ return redactValueDetectors(value);
27234
+ }
27235
+ function redactError(error) {
27236
+ const safe = new Error(redactValueDetectors(error.message ?? ""));
27237
+ safe.name = error.name;
27238
+ safe.stack = typeof error.stack === "string" ? redactValueDetectors(error.stack) : undefined;
27239
+ return safe;
27240
+ }
27241
+ function nameTokens(name) {
27242
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s._-]+/).map((t) => t.toLowerCase()).filter(Boolean);
27243
+ }
27244
+ function isSensitiveName(name) {
27245
+ const tokens = nameTokens(name);
27246
+ for (let i = 0;i < tokens.length; i++) {
27247
+ const token = tokens[i];
27248
+ if (SENSITIVE_NAME_TOKENS.has(token)) {
27249
+ return true;
27250
+ }
27251
+ if (token === "key" || token === "keys") {
27252
+ const prev = tokens[i - 1];
27253
+ if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
27254
+ return true;
27255
+ }
27256
+ }
27257
+ }
27258
+ return false;
27259
+ }
27260
+ function redactProperty(name, value) {
27261
+ if (value === undefined || value === null) {
27262
+ return;
27263
+ }
27264
+ if (isSensitiveName(name)) {
27265
+ return REDACTED;
27266
+ }
27267
+ if (typeof value === "boolean" || typeof value === "number") {
27268
+ return value;
27269
+ }
27270
+ if (typeof value !== "string") {
27271
+ return "[OBJECT]";
27272
+ }
27273
+ return redactValueDetectors(value);
27274
+ }
27275
+ function redactProperties(properties) {
27276
+ const out = {};
27277
+ for (const [name, value] of Object.entries(properties)) {
27278
+ const redacted = redactProperty(name, value);
27279
+ if (redacted !== undefined) {
27280
+ out[name] = redacted;
27281
+ }
27282
+ }
27283
+ return out;
27284
+ }
27285
+
27118
27286
  // ../common/src/telemetry/telemetry-service.ts
27287
+ var TELEMETRY_OPERATION_ID_PROPERTY = "uip.trace.operation_id";
27288
+ var TELEMETRY_PARENT_ID_PROPERTY = "uip.trace.parent_id";
27289
+ var TELEMETRY_SPAN_ID_PROPERTY = "uip.trace.span_id";
27290
+
27119
27291
  class TelemetryService {
27120
27292
  telemetryProvider;
27121
27293
  contextStorage;
@@ -27142,11 +27314,15 @@ class TelemetryService {
27142
27314
  trackException(error, properties) {
27143
27315
  const context = this.getCurrentContext();
27144
27316
  const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
27145
- this.telemetryProvider.trackException(error, enrichedProperties);
27317
+ this.telemetryProvider.trackException(redactError(error), enrichedProperties);
27146
27318
  }
27147
27319
  async trackRequest(name, fn, properties) {
27320
+ const parentContext = this.getCurrentContext();
27321
+ const operationId = parentContext?.operationId ?? this.operationId ?? getTelemetryOperationId();
27322
+ const parentId = parentContext ? parentContext.id : this.inboundParentIdFor(operationId);
27148
27323
  const context = {
27149
- operationId: this.operationId ?? this.generateId(),
27324
+ operationId,
27325
+ ...parentId !== undefined ? { parentId } : {},
27150
27326
  id: this.generateId()
27151
27327
  };
27152
27328
  const startTime = performance.now();
@@ -27164,6 +27340,45 @@ class TelemetryService {
27164
27340
  throw error;
27165
27341
  }
27166
27342
  }
27343
+ trackRequestResult(name, durationMs, success, properties, context) {
27344
+ const requestContext = context ?? {
27345
+ operationId: this.operationId ?? getTelemetryOperationId(),
27346
+ id: this.generateId()
27347
+ };
27348
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, requestContext);
27349
+ this.telemetryProvider.trackRequest(name, durationMs, success, enrichedProperties);
27350
+ }
27351
+ createRequestContext() {
27352
+ const operationId = this.operationId ?? getTelemetryOperationId();
27353
+ const parentId = this.inboundParentIdFor(operationId);
27354
+ return {
27355
+ operationId,
27356
+ ...parentId !== undefined ? { parentId } : {},
27357
+ id: this.generateId()
27358
+ };
27359
+ }
27360
+ inboundParentIdFor(operationId) {
27361
+ const inbound = getInboundTraceContext();
27362
+ return inbound && inbound.traceId === operationId ? inbound.parentSpanId : undefined;
27363
+ }
27364
+ runWithContext(context, fn) {
27365
+ return this.contextStorage.run(context, fn);
27366
+ }
27367
+ createDependencyContext() {
27368
+ const parentContext = this.getCurrentContext();
27369
+ if (!parentContext) {
27370
+ return;
27371
+ }
27372
+ return {
27373
+ operationId: parentContext.operationId,
27374
+ parentId: parentContext.id,
27375
+ id: this.generateId()
27376
+ };
27377
+ }
27378
+ trackDependencyResult(name, type2, durationMs, success, properties, context, resultCode) {
27379
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
27380
+ this.telemetryProvider.trackDependency(redactValue(name), type2, durationMs, success, enrichedProperties, resultCode);
27381
+ }
27167
27382
  async trackDependencyOperation(name, type2, fn, properties) {
27168
27383
  const parentContext = this.getCurrentContext();
27169
27384
  if (!parentContext) {
@@ -27200,8 +27415,12 @@ class TelemetryService {
27200
27415
  ...getExecutionContextTelemetryProperties(),
27201
27416
  ...globalProperties,
27202
27417
  ...this.defaultProperties,
27203
- ...properties,
27204
- ...context
27418
+ ...redactProperties(properties ?? {}),
27419
+ ...context ? {
27420
+ [TELEMETRY_OPERATION_ID_PROPERTY]: context.operationId,
27421
+ ...context.parentId !== undefined ? { [TELEMETRY_PARENT_ID_PROPERTY]: context.parentId } : {},
27422
+ [TELEMETRY_SPAN_ID_PROPERTY]: context.id
27423
+ } : {}
27205
27424
  };
27206
27425
  if (sessionId === undefined) {
27207
27426
  delete enriched[TELEMETRY_SESSION_ID_PROPERTY];
@@ -27211,7 +27430,16 @@ class TelemetryService {
27211
27430
  return enriched;
27212
27431
  }
27213
27432
  generateId() {
27214
- return crypto.randomUUID().replaceAll("-", "");
27433
+ const bytes = new Uint8Array(8);
27434
+ let hex = "";
27435
+ do {
27436
+ crypto.getRandomValues(bytes);
27437
+ hex = "";
27438
+ for (const byte of bytes) {
27439
+ hex += byte.toString(16).padStart(2, "0");
27440
+ }
27441
+ } while (/^0+$/.test(hex));
27442
+ return hex;
27215
27443
  }
27216
27444
  }
27217
27445
  // ../common/src/telemetry/node-appinsights-telemetry-provider.ts
@@ -27913,152 +28141,25 @@ function buildCommandTelemetryAttribution(commandPath, skillSource) {
27913
28141
  };
27914
28142
  }
27915
28143
 
27916
- // ../common/src/telemetry/pii-redactor.ts
27917
- var REDACTED = "[REDACTED]";
27918
- var MAX_VALUE_LENGTH = 200;
27919
- var SENSITIVE_NAME_TOKENS = new Set([
27920
- "token",
27921
- "tokens",
27922
- "secret",
27923
- "secrets",
27924
- "password",
27925
- "passwords",
27926
- "pwd",
27927
- "credential",
27928
- "credentials",
27929
- "auth",
27930
- "authentication",
27931
- "authorization",
27932
- "authority",
27933
- "cert",
27934
- "certificate",
27935
- "certificates"
27936
- ]);
27937
- var SENSITIVE_KEY_PREFIXES = new Set([
27938
- "api",
27939
- "access",
27940
- "client",
27941
- "private",
27942
- "public",
27943
- "signing",
27944
- "encryption",
27945
- "session",
27946
- "master",
27947
- "shared",
27948
- "root",
27949
- "ssh",
27950
- "rsa",
27951
- "aes",
27952
- "hmac",
27953
- "oauth"
27954
- ]);
27955
- var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
27956
- var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
27957
- var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
27958
- var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
27959
- var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
27960
- var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
27961
- var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
27962
- function shortHash(input) {
27963
- let hash = 2166136261;
27964
- for (let i = 0;i < input.length; i++) {
27965
- hash ^= input.charCodeAt(i);
27966
- hash = Math.imul(hash, 16777619);
27967
- }
27968
- return (hash >>> 0).toString(16).padStart(8, "0");
27969
- }
27970
- function redactUrl(raw) {
27971
- try {
27972
- const url = new URL(raw);
27973
- return `${url.protocol}//${url.host}`;
27974
- } catch {
27975
- return `url#${shortHash(raw)}`;
27976
- }
27977
- }
27978
- function redactValueDetectors(value) {
27979
- let out = value;
27980
- out = out.replace(JWT_PATTERN, () => REDACTED);
27981
- out = out.replace(URL_PATTERN, (match) => {
27982
- const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
27983
- const core2 = trailing ? match.slice(0, -trailing.length) : match;
27984
- return `${redactUrl(core2)}${trailing}`;
27985
- });
27986
- out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
27987
- out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
27988
- out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
27989
- out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
27990
- if (out.length > MAX_VALUE_LENGTH) {
27991
- out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
27992
- }
27993
- return out;
27994
- }
27995
- function nameTokens(name) {
27996
- return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).map((t) => t.toLowerCase()).filter(Boolean);
27997
- }
27998
- function isSensitiveName(name) {
27999
- const tokens = nameTokens(name);
28000
- for (let i = 0;i < tokens.length; i++) {
28001
- const token = tokens[i];
28002
- if (SENSITIVE_NAME_TOKENS.has(token)) {
28003
- return true;
28004
- }
28005
- if (token === "key" || token === "keys") {
28006
- const prev = tokens[i - 1];
28007
- if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
28008
- return true;
28009
- }
28010
- }
28011
- }
28012
- return false;
28013
- }
28014
- function redactProperty(name, value) {
28015
- if (value === undefined || value === null) {
28016
- return;
28017
- }
28018
- if (isSensitiveName(name)) {
28019
- return REDACTED;
28020
- }
28021
- if (typeof value === "boolean" || typeof value === "number") {
28022
- return value;
28023
- }
28024
- if (typeof value !== "string") {
28025
- return "[OBJECT]";
28026
- }
28027
- return redactValueDetectors(value);
28028
- }
28029
- function redactProperties(properties) {
28030
- const out = {};
28031
- for (const [name, value] of Object.entries(properties)) {
28032
- const redacted = redactProperty(name, value);
28033
- if (redacted !== undefined) {
28034
- out[name] = redacted;
28035
- }
28036
- }
28037
- return out;
28038
- }
28039
-
28040
28144
  // ../common/src/trackedAction.ts
28041
28145
  var pollSignalSlot = singleton("PollSignal");
28042
28146
  var cliErrorCodeValues = new Set(CLI_ERROR_CODES);
28043
28147
  var retryHintValues = new Set(RETRY_HINTS);
28148
+ var TELEMETRY_COMMAND_ARG_PREFIX = "uip.cmd.arg.";
28044
28149
  function extractCommandParams(cmd) {
28045
28150
  const params = {};
28151
+ const add2 = (name, value) => {
28152
+ if (name && value !== undefined) {
28153
+ params[`${TELEMETRY_COMMAND_ARG_PREFIX}${name}`] = value;
28154
+ }
28155
+ };
28046
28156
  const registered = cmd.registeredArguments ?? [];
28047
28157
  const processed = cmd.processedArgs ?? [];
28048
28158
  for (let i = 0;i < registered.length; i++) {
28049
- const value = processed[i];
28050
- if (value === undefined) {
28051
- continue;
28052
- }
28053
- const name = registered[i].name();
28054
- if (name) {
28055
- params[name] = value;
28056
- }
28159
+ add2(registered[i].name(), processed[i]);
28057
28160
  }
28058
28161
  for (const [key, value] of Object.entries(cmd.opts())) {
28059
- if (value !== undefined) {
28060
- params[key] = value;
28061
- }
28162
+ add2(key, value);
28062
28163
  }
28063
28164
  return params;
28064
28165
  }
@@ -28101,11 +28202,12 @@ Command.prototype.trackedAction = function(context, fn, properties) {
28101
28202
  return this.action(async (...args) => {
28102
28203
  const telemetryName = deriveCommandPath(command);
28103
28204
  const props = typeof properties === "function" ? properties(...args) : properties;
28205
+ const requestContext = telemetry.createRequestContext();
28104
28206
  const startTime = performance.now();
28105
28207
  let errorMessage;
28106
28208
  let fallbackExitCode = EXIT_CODES.Success;
28107
28209
  clearRecordedCommandFailureTelemetry();
28108
- const [error] = await catchError(fn(...args));
28210
+ const [error] = await catchError(telemetry.runWithContext(requestContext, () => fn(...args)));
28109
28211
  if (error) {
28110
28212
  errorMessage = error instanceof Error ? error.message : String(error);
28111
28213
  logger.debug(`[trackedAction] ${telemetryName} failed: ${errorMessage}`);
@@ -28141,16 +28243,21 @@ Command.prototype.trackedAction = function(context, fn, properties) {
28141
28243
  recordedFailure,
28142
28244
  pollSignal: context.pollSignal
28143
28245
  });
28144
- telemetry.trackEvent(telemetryName, redactProperties({
28145
- ...extractCommandParams(command),
28246
+ const commandParams = extractCommandParams(command);
28247
+ if (props) {
28248
+ for (const key of Object.keys(props)) {
28249
+ delete commandParams[`${TELEMETRY_COMMAND_ARG_PREFIX}${key}`];
28250
+ }
28251
+ }
28252
+ const baseProperties = redactProperties({
28253
+ ...commandParams,
28146
28254
  ...props,
28147
28255
  ...buildCommandTelemetryAttribution(telemetryName, process.env.UIPATH_SKILL),
28148
28256
  command: "true",
28149
- duration: String(durationMs),
28150
- success: String(success),
28151
28257
  ...terminalTelemetry,
28152
28258
  ...errorMessage ? { errorMessage } : {}
28153
- }));
28259
+ });
28260
+ telemetry.trackRequestResult(telemetryName, durationMs, success, baseProperties, requestContext);
28154
28261
  });
28155
28262
  };
28156
28263
  // ../common/src/console-guard.ts
@@ -29776,4 +29883,4 @@ export {
29776
29883
  codedagentInitAsync
29777
29884
  };
29778
29885
 
29779
- //# debugId=E83863A3D272AC9764756E2164756E21
29886
+ //# debugId=C89AA6E7799E7E6D64756E2164756E21
package/dist/tool.js CHANGED
@@ -27104,11 +27104,36 @@ class NodeContextStorage {
27104
27104
  return this.storage.getStore();
27105
27105
  }
27106
27106
  }
27107
+ // ../common/src/telemetry/trace-context.ts
27108
+ var TELEMETRY_TRACEPARENT_ENV = "TRACEPARENT";
27109
+ var TRACEPARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
27110
+ function getProcessEnv() {
27111
+ return globalThis.process?.env;
27112
+ }
27113
+ function parseInboundTraceparent(value) {
27114
+ if (!value) {
27115
+ return;
27116
+ }
27117
+ const match = TRACEPARENT_PATTERN.exec(value.trim().toLowerCase());
27118
+ if (!match) {
27119
+ return;
27120
+ }
27121
+ const [, traceId, parentSpanId] = match;
27122
+ if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId)) {
27123
+ return;
27124
+ }
27125
+ return { traceId, parentSpanId };
27126
+ }
27127
+ function getInboundTraceContext() {
27128
+ return parseInboundTraceparent(getProcessEnv()?.[TELEMETRY_TRACEPARENT_ENV]);
27129
+ }
27130
+
27107
27131
  // ../common/src/telemetry/session-id.ts
27108
27132
  var TELEMETRY_SESSION_ID_ENV = "UIPATH_SESSION_ID";
27109
27133
  var TELEMETRY_SESSION_ID_PROPERTY = "session_id";
27110
27134
  var telemetrySessionIdSlot = singleton("TelemetrySessionId");
27111
- function getProcessEnv() {
27135
+ var telemetryOperationIdSlot = singleton("TelemetryOperationId");
27136
+ function getProcessEnv2() {
27112
27137
  return globalThis.process?.env;
27113
27138
  }
27114
27139
  function normalizeSessionId(value) {
@@ -27119,18 +27144,165 @@ function normalizeSessionId(value) {
27119
27144
  return trimmed || undefined;
27120
27145
  }
27121
27146
  function getConfiguredTelemetrySessionId() {
27122
- return normalizeSessionId(getProcessEnv()?.[TELEMETRY_SESSION_ID_ENV]);
27147
+ return normalizeSessionId(getProcessEnv2()?.[TELEMETRY_SESSION_ID_ENV]);
27123
27148
  }
27124
27149
  function resolveTelemetrySessionId(existingSessionId) {
27125
27150
  return getConfiguredTelemetrySessionId() ?? normalizeSessionId(existingSessionId);
27126
27151
  }
27152
+ function getTelemetryOperationId() {
27153
+ const existing = telemetryOperationIdSlot.get();
27154
+ if (existing) {
27155
+ return existing;
27156
+ }
27157
+ const inboundTraceId = getInboundTraceContext()?.traceId;
27158
+ const generated = inboundTraceId ?? crypto.randomUUID().replaceAll("-", "");
27159
+ telemetryOperationIdSlot.set(generated);
27160
+ return generated;
27161
+ }
27127
27162
  // ../common/src/telemetry/global-telemetry-properties.ts
27128
27163
  var telemetryPropsSlot = singleton("TelemetryDefaultProps");
27129
27164
  function getGlobalTelemetryProperties() {
27130
27165
  return telemetryPropsSlot.get();
27131
27166
  }
27132
27167
 
27168
+ // ../common/src/telemetry/pii-redactor.ts
27169
+ var REDACTED = "[REDACTED]";
27170
+ var MAX_VALUE_LENGTH = 200;
27171
+ var SENSITIVE_NAME_TOKENS = new Set([
27172
+ "token",
27173
+ "tokens",
27174
+ "secret",
27175
+ "secrets",
27176
+ "password",
27177
+ "passwords",
27178
+ "pwd",
27179
+ "credential",
27180
+ "credentials",
27181
+ "auth",
27182
+ "authentication",
27183
+ "authorization",
27184
+ "authority",
27185
+ "cert",
27186
+ "certificate",
27187
+ "certificates"
27188
+ ]);
27189
+ var SENSITIVE_KEY_PREFIXES = new Set([
27190
+ "api",
27191
+ "access",
27192
+ "client",
27193
+ "private",
27194
+ "public",
27195
+ "signing",
27196
+ "encryption",
27197
+ "session",
27198
+ "master",
27199
+ "shared",
27200
+ "root",
27201
+ "ssh",
27202
+ "rsa",
27203
+ "aes",
27204
+ "hmac",
27205
+ "oauth"
27206
+ ]);
27207
+ var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
27208
+ var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
27209
+ var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
27210
+ var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
27211
+ var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
27212
+ var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
27213
+ var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
27214
+ function shortHash(input) {
27215
+ let hash = 2166136261;
27216
+ for (let i = 0;i < input.length; i++) {
27217
+ hash ^= input.charCodeAt(i);
27218
+ hash = Math.imul(hash, 16777619);
27219
+ }
27220
+ return (hash >>> 0).toString(16).padStart(8, "0");
27221
+ }
27222
+ function redactUrl(raw) {
27223
+ try {
27224
+ const url = new URL(raw);
27225
+ return `${url.protocol}//${url.host}`;
27226
+ } catch {
27227
+ return `url#${shortHash(raw)}`;
27228
+ }
27229
+ }
27230
+ function redactValueDetectors(value) {
27231
+ let out = value;
27232
+ out = out.replace(JWT_PATTERN, () => REDACTED);
27233
+ out = out.replace(URL_PATTERN, (match) => {
27234
+ const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
27235
+ const core2 = trailing ? match.slice(0, -trailing.length) : match;
27236
+ return `${redactUrl(core2)}${trailing}`;
27237
+ });
27238
+ out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
27239
+ out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
27240
+ out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
27241
+ out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
27242
+ if (out.length > MAX_VALUE_LENGTH) {
27243
+ out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
27244
+ }
27245
+ return out;
27246
+ }
27247
+ function redactValue(value) {
27248
+ return redactValueDetectors(value);
27249
+ }
27250
+ function redactError(error) {
27251
+ const safe = new Error(redactValueDetectors(error.message ?? ""));
27252
+ safe.name = error.name;
27253
+ safe.stack = typeof error.stack === "string" ? redactValueDetectors(error.stack) : undefined;
27254
+ return safe;
27255
+ }
27256
+ function nameTokens(name) {
27257
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s._-]+/).map((t) => t.toLowerCase()).filter(Boolean);
27258
+ }
27259
+ function isSensitiveName(name) {
27260
+ const tokens = nameTokens(name);
27261
+ for (let i = 0;i < tokens.length; i++) {
27262
+ const token = tokens[i];
27263
+ if (SENSITIVE_NAME_TOKENS.has(token)) {
27264
+ return true;
27265
+ }
27266
+ if (token === "key" || token === "keys") {
27267
+ const prev = tokens[i - 1];
27268
+ if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
27269
+ return true;
27270
+ }
27271
+ }
27272
+ }
27273
+ return false;
27274
+ }
27275
+ function redactProperty(name, value) {
27276
+ if (value === undefined || value === null) {
27277
+ return;
27278
+ }
27279
+ if (isSensitiveName(name)) {
27280
+ return REDACTED;
27281
+ }
27282
+ if (typeof value === "boolean" || typeof value === "number") {
27283
+ return value;
27284
+ }
27285
+ if (typeof value !== "string") {
27286
+ return "[OBJECT]";
27287
+ }
27288
+ return redactValueDetectors(value);
27289
+ }
27290
+ function redactProperties(properties) {
27291
+ const out = {};
27292
+ for (const [name, value] of Object.entries(properties)) {
27293
+ const redacted = redactProperty(name, value);
27294
+ if (redacted !== undefined) {
27295
+ out[name] = redacted;
27296
+ }
27297
+ }
27298
+ return out;
27299
+ }
27300
+
27133
27301
  // ../common/src/telemetry/telemetry-service.ts
27302
+ var TELEMETRY_OPERATION_ID_PROPERTY = "uip.trace.operation_id";
27303
+ var TELEMETRY_PARENT_ID_PROPERTY = "uip.trace.parent_id";
27304
+ var TELEMETRY_SPAN_ID_PROPERTY = "uip.trace.span_id";
27305
+
27134
27306
  class TelemetryService {
27135
27307
  telemetryProvider;
27136
27308
  contextStorage;
@@ -27157,11 +27329,15 @@ class TelemetryService {
27157
27329
  trackException(error, properties) {
27158
27330
  const context = this.getCurrentContext();
27159
27331
  const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
27160
- this.telemetryProvider.trackException(error, enrichedProperties);
27332
+ this.telemetryProvider.trackException(redactError(error), enrichedProperties);
27161
27333
  }
27162
27334
  async trackRequest(name, fn, properties) {
27335
+ const parentContext = this.getCurrentContext();
27336
+ const operationId = parentContext?.operationId ?? this.operationId ?? getTelemetryOperationId();
27337
+ const parentId = parentContext ? parentContext.id : this.inboundParentIdFor(operationId);
27163
27338
  const context = {
27164
- operationId: this.operationId ?? this.generateId(),
27339
+ operationId,
27340
+ ...parentId !== undefined ? { parentId } : {},
27165
27341
  id: this.generateId()
27166
27342
  };
27167
27343
  const startTime = performance.now();
@@ -27179,6 +27355,45 @@ class TelemetryService {
27179
27355
  throw error;
27180
27356
  }
27181
27357
  }
27358
+ trackRequestResult(name, durationMs, success, properties, context) {
27359
+ const requestContext = context ?? {
27360
+ operationId: this.operationId ?? getTelemetryOperationId(),
27361
+ id: this.generateId()
27362
+ };
27363
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, requestContext);
27364
+ this.telemetryProvider.trackRequest(name, durationMs, success, enrichedProperties);
27365
+ }
27366
+ createRequestContext() {
27367
+ const operationId = this.operationId ?? getTelemetryOperationId();
27368
+ const parentId = this.inboundParentIdFor(operationId);
27369
+ return {
27370
+ operationId,
27371
+ ...parentId !== undefined ? { parentId } : {},
27372
+ id: this.generateId()
27373
+ };
27374
+ }
27375
+ inboundParentIdFor(operationId) {
27376
+ const inbound = getInboundTraceContext();
27377
+ return inbound && inbound.traceId === operationId ? inbound.parentSpanId : undefined;
27378
+ }
27379
+ runWithContext(context, fn) {
27380
+ return this.contextStorage.run(context, fn);
27381
+ }
27382
+ createDependencyContext() {
27383
+ const parentContext = this.getCurrentContext();
27384
+ if (!parentContext) {
27385
+ return;
27386
+ }
27387
+ return {
27388
+ operationId: parentContext.operationId,
27389
+ parentId: parentContext.id,
27390
+ id: this.generateId()
27391
+ };
27392
+ }
27393
+ trackDependencyResult(name, type2, durationMs, success, properties, context, resultCode) {
27394
+ const enrichedProperties = this.enrichPropertiesWithContext(properties, context);
27395
+ this.telemetryProvider.trackDependency(redactValue(name), type2, durationMs, success, enrichedProperties, resultCode);
27396
+ }
27182
27397
  async trackDependencyOperation(name, type2, fn, properties) {
27183
27398
  const parentContext = this.getCurrentContext();
27184
27399
  if (!parentContext) {
@@ -27215,8 +27430,12 @@ class TelemetryService {
27215
27430
  ...getExecutionContextTelemetryProperties(),
27216
27431
  ...globalProperties,
27217
27432
  ...this.defaultProperties,
27218
- ...properties,
27219
- ...context
27433
+ ...redactProperties(properties ?? {}),
27434
+ ...context ? {
27435
+ [TELEMETRY_OPERATION_ID_PROPERTY]: context.operationId,
27436
+ ...context.parentId !== undefined ? { [TELEMETRY_PARENT_ID_PROPERTY]: context.parentId } : {},
27437
+ [TELEMETRY_SPAN_ID_PROPERTY]: context.id
27438
+ } : {}
27220
27439
  };
27221
27440
  if (sessionId === undefined) {
27222
27441
  delete enriched[TELEMETRY_SESSION_ID_PROPERTY];
@@ -27226,7 +27445,16 @@ class TelemetryService {
27226
27445
  return enriched;
27227
27446
  }
27228
27447
  generateId() {
27229
- return crypto.randomUUID().replaceAll("-", "");
27448
+ const bytes = new Uint8Array(8);
27449
+ let hex = "";
27450
+ do {
27451
+ crypto.getRandomValues(bytes);
27452
+ hex = "";
27453
+ for (const byte of bytes) {
27454
+ hex += byte.toString(16).padStart(2, "0");
27455
+ }
27456
+ } while (/^0+$/.test(hex));
27457
+ return hex;
27230
27458
  }
27231
27459
  }
27232
27460
  // ../common/src/telemetry/node-appinsights-telemetry-provider.ts
@@ -27928,134 +28156,11 @@ function buildCommandTelemetryAttribution(commandPath, skillSource) {
27928
28156
  };
27929
28157
  }
27930
28158
 
27931
- // ../common/src/telemetry/pii-redactor.ts
27932
- var REDACTED = "[REDACTED]";
27933
- var MAX_VALUE_LENGTH = 200;
27934
- var SENSITIVE_NAME_TOKENS = new Set([
27935
- "token",
27936
- "tokens",
27937
- "secret",
27938
- "secrets",
27939
- "password",
27940
- "passwords",
27941
- "pwd",
27942
- "credential",
27943
- "credentials",
27944
- "auth",
27945
- "authentication",
27946
- "authorization",
27947
- "authority",
27948
- "cert",
27949
- "certificate",
27950
- "certificates"
27951
- ]);
27952
- var SENSITIVE_KEY_PREFIXES = new Set([
27953
- "api",
27954
- "access",
27955
- "client",
27956
- "private",
27957
- "public",
27958
- "signing",
27959
- "encryption",
27960
- "session",
27961
- "master",
27962
- "shared",
27963
- "root",
27964
- "ssh",
27965
- "rsa",
27966
- "aes",
27967
- "hmac",
27968
- "oauth"
27969
- ]);
27970
- var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
27971
- var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
27972
- var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
27973
- var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
27974
- var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
27975
- var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
27976
- var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
27977
- function shortHash(input) {
27978
- let hash = 2166136261;
27979
- for (let i = 0;i < input.length; i++) {
27980
- hash ^= input.charCodeAt(i);
27981
- hash = Math.imul(hash, 16777619);
27982
- }
27983
- return (hash >>> 0).toString(16).padStart(8, "0");
27984
- }
27985
- function redactUrl(raw) {
27986
- try {
27987
- const url = new URL(raw);
27988
- return `${url.protocol}//${url.host}`;
27989
- } catch {
27990
- return `url#${shortHash(raw)}`;
27991
- }
27992
- }
27993
- function redactValueDetectors(value) {
27994
- let out = value;
27995
- out = out.replace(JWT_PATTERN, () => REDACTED);
27996
- out = out.replace(URL_PATTERN, (match) => {
27997
- const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
27998
- const core2 = trailing ? match.slice(0, -trailing.length) : match;
27999
- return `${redactUrl(core2)}${trailing}`;
28000
- });
28001
- out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
28002
- out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
28003
- out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
28004
- out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
28005
- if (out.length > MAX_VALUE_LENGTH) {
28006
- out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
28007
- }
28008
- return out;
28009
- }
28010
- function nameTokens(name) {
28011
- return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).map((t) => t.toLowerCase()).filter(Boolean);
28012
- }
28013
- function isSensitiveName(name) {
28014
- const tokens = nameTokens(name);
28015
- for (let i = 0;i < tokens.length; i++) {
28016
- const token = tokens[i];
28017
- if (SENSITIVE_NAME_TOKENS.has(token)) {
28018
- return true;
28019
- }
28020
- if (token === "key" || token === "keys") {
28021
- const prev = tokens[i - 1];
28022
- if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
28023
- return true;
28024
- }
28025
- }
28026
- }
28027
- return false;
28028
- }
28029
- function redactProperty(name, value) {
28030
- if (value === undefined || value === null) {
28031
- return;
28032
- }
28033
- if (isSensitiveName(name)) {
28034
- return REDACTED;
28035
- }
28036
- if (typeof value === "boolean" || typeof value === "number") {
28037
- return value;
28038
- }
28039
- if (typeof value !== "string") {
28040
- return "[OBJECT]";
28041
- }
28042
- return redactValueDetectors(value);
28043
- }
28044
- function redactProperties(properties) {
28045
- const out = {};
28046
- for (const [name, value] of Object.entries(properties)) {
28047
- const redacted = redactProperty(name, value);
28048
- if (redacted !== undefined) {
28049
- out[name] = redacted;
28050
- }
28051
- }
28052
- return out;
28053
- }
28054
-
28055
28159
  // ../common/src/trackedAction.ts
28056
28160
  var pollSignalSlot = singleton("PollSignal");
28057
28161
  var cliErrorCodeValues = new Set(CLI_ERROR_CODES);
28058
28162
  var retryHintValues = new Set(RETRY_HINTS);
28163
+ var TELEMETRY_COMMAND_ARG_PREFIX = "uip.cmd.arg.";
28059
28164
  var processContext = {
28060
28165
  exit: (code) => {
28061
28166
  process.exitCode = code;
@@ -28066,22 +28171,18 @@ var processContext = {
28066
28171
  };
28067
28172
  function extractCommandParams(cmd) {
28068
28173
  const params = {};
28174
+ const add2 = (name, value) => {
28175
+ if (name && value !== undefined) {
28176
+ params[`${TELEMETRY_COMMAND_ARG_PREFIX}${name}`] = value;
28177
+ }
28178
+ };
28069
28179
  const registered = cmd.registeredArguments ?? [];
28070
28180
  const processed = cmd.processedArgs ?? [];
28071
28181
  for (let i = 0;i < registered.length; i++) {
28072
- const value = processed[i];
28073
- if (value === undefined) {
28074
- continue;
28075
- }
28076
- const name = registered[i].name();
28077
- if (name) {
28078
- params[name] = value;
28079
- }
28182
+ add2(registered[i].name(), processed[i]);
28080
28183
  }
28081
28184
  for (const [key, value] of Object.entries(cmd.opts())) {
28082
- if (value !== undefined) {
28083
- params[key] = value;
28084
- }
28185
+ add2(key, value);
28085
28186
  }
28086
28187
  return params;
28087
28188
  }
@@ -28124,11 +28225,12 @@ Command.prototype.trackedAction = function(context, fn, properties) {
28124
28225
  return this.action(async (...args) => {
28125
28226
  const telemetryName = deriveCommandPath(command);
28126
28227
  const props = typeof properties === "function" ? properties(...args) : properties;
28228
+ const requestContext = telemetry.createRequestContext();
28127
28229
  const startTime = performance.now();
28128
28230
  let errorMessage;
28129
28231
  let fallbackExitCode = EXIT_CODES.Success;
28130
28232
  clearRecordedCommandFailureTelemetry();
28131
- const [error] = await catchError(fn(...args));
28233
+ const [error] = await catchError(telemetry.runWithContext(requestContext, () => fn(...args)));
28132
28234
  if (error) {
28133
28235
  errorMessage = error instanceof Error ? error.message : String(error);
28134
28236
  logger.debug(`[trackedAction] ${telemetryName} failed: ${errorMessage}`);
@@ -28164,16 +28266,21 @@ Command.prototype.trackedAction = function(context, fn, properties) {
28164
28266
  recordedFailure,
28165
28267
  pollSignal: context.pollSignal
28166
28268
  });
28167
- telemetry.trackEvent(telemetryName, redactProperties({
28168
- ...extractCommandParams(command),
28269
+ const commandParams = extractCommandParams(command);
28270
+ if (props) {
28271
+ for (const key of Object.keys(props)) {
28272
+ delete commandParams[`${TELEMETRY_COMMAND_ARG_PREFIX}${key}`];
28273
+ }
28274
+ }
28275
+ const baseProperties = redactProperties({
28276
+ ...commandParams,
28169
28277
  ...props,
28170
28278
  ...buildCommandTelemetryAttribution(telemetryName, process.env.UIPATH_SKILL),
28171
28279
  command: "true",
28172
- duration: String(durationMs),
28173
- success: String(success),
28174
28280
  ...terminalTelemetry,
28175
28281
  ...errorMessage ? { errorMessage } : {}
28176
- }));
28282
+ });
28283
+ telemetry.trackRequestResult(telemetryName, durationMs, success, baseProperties, requestContext);
28177
28284
  });
28178
28285
  };
28179
28286
  // ../common/src/console-guard.ts
@@ -30237,7 +30344,7 @@ Searching for Python installations: ${allowedVersions}`);
30237
30344
  var package_default = {
30238
30345
  name: "@uipath/codedagent-tool",
30239
30346
  license: "MIT",
30240
- version: "1.198.0-preview.95",
30347
+ version: "1.198.0",
30241
30348
  description: "Build, run, deploy, and manage AI Agents.",
30242
30349
  keywords: [
30243
30350
  "cli-tool",
@@ -31065,4 +31172,4 @@ export {
31065
31172
  metadata
31066
31173
  };
31067
31174
 
31068
- //# debugId=C2E495506CB77BF464756E2164756E21
31175
+ //# debugId=0A857E6EB2FBA1BB64756E2164756E21
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uipath/codedagent-tool",
3
3
  "license": "MIT",
4
- "version": "1.198.0-preview.95",
4
+ "version": "1.198.0",
5
5
  "description": "Build, run, deploy, and manage AI Agents.",
6
6
  "keywords": [
7
7
  "cli-tool",
@@ -32,5 +32,5 @@
32
32
  "publishConfig": {
33
33
  "registry": "https://registry.npmjs.org/"
34
34
  },
35
- "gitHead": "7f6f14e06688fe417ecaac94186ab795a9106caa"
35
+ "gitHead": "1fadf03d7a8dd102742571dff569fdac11808afb"
36
36
  }