@uipath/coder-tool 1.204.0-preview.255 → 1.205.0-preview.256
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +1 -1
- package/dist/{tool-y65sryad.js → tool-wpfk336s.js} +232 -37
- package/dist/tool.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -101,4 +101,4 @@ bunx vitest run packages/coder-tool/src # unit tests
|
|
|
101
101
|
node packages/coder-tool/dist/index.js -p "hi" # standalone smoke test
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
Scenario coverage lives in [`scenarios/coder-tool/coding-agent.md`](../../scenarios/coder-tool/coding-agent.md)
|
|
104
|
+
Scenario coverage lives in [`scenarios/coder-tool/coding-agent.md`](../../scenarios/coder-tool/coding-agent.md). `tests/coding-agent.e2e.test.ts` runs all seven scenarios; S4 needs a tenant with a chat model and is excluded on AS/ETE.
|
package/dist/index.js
CHANGED
|
@@ -2277,6 +2277,16 @@ class NodeFileSystem {
|
|
|
2277
2277
|
async rename(oldPath, newPath) {
|
|
2278
2278
|
await fs.rename(oldPath, newPath);
|
|
2279
2279
|
}
|
|
2280
|
+
async isSymbolicLink(filePath) {
|
|
2281
|
+
try {
|
|
2282
|
+
return (await fs.lstat(filePath)).isSymbolicLink();
|
|
2283
|
+
} catch (error) {
|
|
2284
|
+
if (this.isEnoent(error) || this.hasErrnoCode(error, "ENOTDIR")) {
|
|
2285
|
+
return false;
|
|
2286
|
+
}
|
|
2287
|
+
throw error;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2280
2290
|
async realpath(filePath) {
|
|
2281
2291
|
try {
|
|
2282
2292
|
return await fs.realpath(filePath);
|
|
@@ -2984,7 +2994,7 @@ function setGlobalLogFilePath(path2) {
|
|
|
2984
2994
|
function getGlobalLogFilePath() {
|
|
2985
2995
|
return logFilePathSlot.get("");
|
|
2986
2996
|
}
|
|
2987
|
-
var DEFAULT_LOG_LEVEL =
|
|
2997
|
+
var DEFAULT_LOG_LEVEL = 2 /* WARN */;
|
|
2988
2998
|
|
|
2989
2999
|
class SimpleLogger {
|
|
2990
3000
|
__brand = "SimpleLogger";
|
|
@@ -3251,7 +3261,9 @@ var ErrorDimensions = {
|
|
|
3251
3261
|
Result: "Result",
|
|
3252
3262
|
ErrorCode: "ErrorCode",
|
|
3253
3263
|
Retry: "Retry",
|
|
3254
|
-
ErrorMessage: "ErrorMessage"
|
|
3264
|
+
ErrorMessage: "ErrorMessage",
|
|
3265
|
+
HttpStatus: "HttpStatus",
|
|
3266
|
+
UpstreamErrorCode: "UpstreamErrorCode"
|
|
3255
3267
|
};
|
|
3256
3268
|
var AuthDimensions = {
|
|
3257
3269
|
AuthenticationMethod: "AuthenticationMethod",
|
|
@@ -4239,7 +4251,9 @@ var CLI_ERROR_CODES = [
|
|
|
4239
4251
|
"timeout",
|
|
4240
4252
|
"server_error",
|
|
4241
4253
|
"method_not_allowed",
|
|
4254
|
+
"not_supported",
|
|
4242
4255
|
"configuration_error",
|
|
4256
|
+
"execution_failed",
|
|
4243
4257
|
"unknown_error"
|
|
4244
4258
|
];
|
|
4245
4259
|
var RETRY_HINTS = [
|
|
@@ -5196,7 +5210,9 @@ var OutputFormatter;
|
|
|
5196
5210
|
[ErrorDimensions.Result]: data.Result,
|
|
5197
5211
|
[ErrorDimensions.ErrorCode]: data.ErrorCode,
|
|
5198
5212
|
[ErrorDimensions.Retry]: data.Retry,
|
|
5199
|
-
[ErrorDimensions.ErrorMessage]: data.Message
|
|
5213
|
+
[ErrorDimensions.ErrorMessage]: data.Message,
|
|
5214
|
+
[ErrorDimensions.HttpStatus]: data.Context?.httpStatus?.toString(),
|
|
5215
|
+
[ErrorDimensions.UpstreamErrorCode]: data.Context?.errorCode
|
|
5200
5216
|
});
|
|
5201
5217
|
}
|
|
5202
5218
|
logOutput(normalizeOutputKeys(envelope), getOutputFormat());
|
|
@@ -6053,7 +6069,7 @@ var package_default = {
|
|
|
6053
6069
|
name: "@uipath/coder-tool",
|
|
6054
6070
|
author: "UiPath",
|
|
6055
6071
|
license: "SEE LICENSE IN LICENSE.txt",
|
|
6056
|
-
version: "1.
|
|
6072
|
+
version: "1.205.0-preview.256",
|
|
6057
6073
|
description: "Interactive coding agent (Pi) with UiPath LLM Gateway and BYO provider support.",
|
|
6058
6074
|
publishConfig: {
|
|
6059
6075
|
registry: "https://npm.pkg.github.com/"
|
|
@@ -6202,22 +6218,12 @@ var resolveConfigAsync = async ({
|
|
|
6202
6218
|
baseUrl = DEFAULT_BASE_URL;
|
|
6203
6219
|
}
|
|
6204
6220
|
baseUrl = normalizeAndValidateBaseUrl(baseUrl);
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
clientId = fileAuth.clientId;
|
|
6208
|
-
}
|
|
6209
|
-
if (!clientId) {
|
|
6210
|
-
clientId = DEFAULT_CLIENT_ID;
|
|
6211
|
-
}
|
|
6212
|
-
let clientSecret = customClientSecret;
|
|
6213
|
-
if (!clientSecret && fileAuth.clientSecret) {
|
|
6214
|
-
clientSecret = fileAuth.clientSecret;
|
|
6215
|
-
}
|
|
6216
|
-
const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(clientSecret) || Boolean(customClientAssertion));
|
|
6221
|
+
const clientId = customClientId || DEFAULT_CLIENT_ID;
|
|
6222
|
+
const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(customClientSecret) || Boolean(customClientAssertion));
|
|
6217
6223
|
const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
|
|
6218
6224
|
return {
|
|
6219
6225
|
clientId,
|
|
6220
|
-
clientSecret,
|
|
6226
|
+
clientSecret: customClientSecret,
|
|
6221
6227
|
scopes,
|
|
6222
6228
|
baseUrl,
|
|
6223
6229
|
authorizationEndpoint: `${baseUrl}/identity_/connect/authorize`,
|
|
@@ -6391,6 +6397,16 @@ var resolveIdentityType = (claims, authFlow, email) => {
|
|
|
6391
6397
|
}
|
|
6392
6398
|
return;
|
|
6393
6399
|
};
|
|
6400
|
+
var resolveApplicationSubtype = (claims, authFlow) => {
|
|
6401
|
+
switch (asString(claims?.sub_type)) {
|
|
6402
|
+
case "service.external":
|
|
6403
|
+
return "External";
|
|
6404
|
+
case "service.internal":
|
|
6405
|
+
return "Internal";
|
|
6406
|
+
default:
|
|
6407
|
+
return authFlow === "client_credentials" || authFlow === "federated_credentials" ? "External" : undefined;
|
|
6408
|
+
}
|
|
6409
|
+
};
|
|
6394
6410
|
var looksLikeEmail = (value) => value?.includes("@") ?? false;
|
|
6395
6411
|
var pickEmail = (claims) => {
|
|
6396
6412
|
for (const candidate of [claims?.email, claims?.preferred_username]) {
|
|
@@ -6432,6 +6448,12 @@ var resolveSessionIdentity = (accessToken, authFlow) => {
|
|
|
6432
6448
|
const clientId = asString(claims?.client_id);
|
|
6433
6449
|
if (clientId)
|
|
6434
6450
|
identity.clientId = clientId;
|
|
6451
|
+
const subType = asString(claims?.sub_type);
|
|
6452
|
+
if (subType)
|
|
6453
|
+
identity.subType = subType;
|
|
6454
|
+
const applicationSubtype = resolveApplicationSubtype(claims, authFlow);
|
|
6455
|
+
if (applicationSubtype)
|
|
6456
|
+
identity.applicationSubtype = applicationSubtype;
|
|
6435
6457
|
return identity;
|
|
6436
6458
|
};
|
|
6437
6459
|
var readTokenScopes = (accessToken) => accessToken ? pickScopes(decodeClaims(accessToken)) : undefined;
|
|
@@ -6724,6 +6746,40 @@ var tryRobotClientFallback = async (options = {}) => {
|
|
|
6724
6746
|
}
|
|
6725
6747
|
};
|
|
6726
6748
|
|
|
6749
|
+
// ../auth/src/tenantSelection.ts
|
|
6750
|
+
var LOGIN_STATUS_HINT = "Run 'uip login status' to see the organization the CLI is signed in to.";
|
|
6751
|
+
var organizationHint = (organizationId) => `The request used '${organizationId}' as the organization. ${LOGIN_STATUS_HINT}`;
|
|
6752
|
+
var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
|
|
6753
|
+
var describeNonJsonResponse = (organizationId, response, parseError) => {
|
|
6754
|
+
if (response.redirected) {
|
|
6755
|
+
return `Could not find organization '${organizationId}': the request was ` + `redirected to a sign-in page instead of the organization's tenant ` + `list. ${LOGIN_STATUS_HINT}`;
|
|
6756
|
+
}
|
|
6757
|
+
const contentType = response.headers.get("content-type") ?? "unknown";
|
|
6758
|
+
return `The organization service returned a '${contentType}' response instead ` + `of JSON: ${parseError.message}. ${organizationHint(organizationId)}`;
|
|
6759
|
+
};
|
|
6760
|
+
var fetchTenantsAndOrganizations = async (baseUrl, accessToken, organizationId, signal) => {
|
|
6761
|
+
const url = `${baseUrl}/${organizationId}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo`;
|
|
6762
|
+
const response = await fetch(url, {
|
|
6763
|
+
headers: {
|
|
6764
|
+
Authorization: `Bearer ${accessToken}`
|
|
6765
|
+
},
|
|
6766
|
+
...signal ? { signal } : {}
|
|
6767
|
+
});
|
|
6768
|
+
if (!response.ok) {
|
|
6769
|
+
if (response.status === 401) {
|
|
6770
|
+
throw new Error(`Unauthorized: the access token was rejected, it was not ` + `issued for organization '${organizationId}', or ` + `'${organizationId}' was not accepted as an organization ` + `URL segment in this environment. ` + LOGIN_STATUS_HINT);
|
|
6771
|
+
}
|
|
6772
|
+
const errorText = await response.text();
|
|
6773
|
+
const message = `Failed to get tenants and organizations: ${response.status} ${errorText}`;
|
|
6774
|
+
throw new Error(IDENTIFIER_STATUSES.has(response.status) ? `${message}. ${organizationHint(organizationId)}` : message);
|
|
6775
|
+
}
|
|
6776
|
+
const [parseError, data] = await catchError2(response.json());
|
|
6777
|
+
if (parseError) {
|
|
6778
|
+
throw new Error(describeNonJsonResponse(organizationId, response, parseError));
|
|
6779
|
+
}
|
|
6780
|
+
return data;
|
|
6781
|
+
};
|
|
6782
|
+
|
|
6727
6783
|
// ../auth/src/tokenRefresh.ts
|
|
6728
6784
|
var TOKEN_REFRESH_REAUTHENTICATE_MESSAGE = "Token refresh failed. Run 'uip login' to re-authenticate.";
|
|
6729
6785
|
|
|
@@ -6936,6 +6992,8 @@ var saveEnvFileAsync = async ({
|
|
|
6936
6992
|
};
|
|
6937
6993
|
|
|
6938
6994
|
// ../auth/src/loginStatus.ts
|
|
6995
|
+
var defaultRobotTenantIdCache = new Map;
|
|
6996
|
+
var ROBOT_TENANT_LOOKUP_TIMEOUT_MS = 5000;
|
|
6939
6997
|
var getLoginStatusAsync = async (options = {}) => {
|
|
6940
6998
|
return getLoginStatusWithDeps(options);
|
|
6941
6999
|
};
|
|
@@ -6948,12 +7006,20 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
|
|
|
6948
7006
|
refreshToken: refreshTokenFn = refreshAccessToken,
|
|
6949
7007
|
resolveConfig = resolveConfigAsync,
|
|
6950
7008
|
robotFallback = tryRobotClientFallback,
|
|
7009
|
+
fetchTenantsAndOrgs = fetchTenantsAndOrganizations,
|
|
7010
|
+
robotTenantIdCache = defaultRobotTenantIdCache,
|
|
7011
|
+
robotTenantLookupTimeoutMs = ROBOT_TENANT_LOOKUP_TIMEOUT_MS,
|
|
6951
7012
|
loadBreaker = loadRefreshBreaker,
|
|
6952
7013
|
saveBreaker = saveRefreshBreaker,
|
|
6953
7014
|
clearBreaker = clearRefreshBreaker
|
|
6954
7015
|
} = deps;
|
|
7016
|
+
const robotDeps = {
|
|
7017
|
+
fetchTenantsAndOrgs,
|
|
7018
|
+
cache: robotTenantIdCache,
|
|
7019
|
+
lookupTimeoutMs: robotTenantLookupTimeoutMs
|
|
7020
|
+
};
|
|
6955
7021
|
if (isRobotAuthEnforced()) {
|
|
6956
|
-
return resolveRobotEnforcedStatus(robotFallback);
|
|
7022
|
+
return resolveRobotEnforcedStatus(robotFallback, robotDeps);
|
|
6957
7023
|
}
|
|
6958
7024
|
if (isEnvAuthEnabled()) {
|
|
6959
7025
|
return readAuthFromEnv();
|
|
@@ -6971,7 +7037,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
|
|
|
6971
7037
|
hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
|
|
6972
7038
|
};
|
|
6973
7039
|
}
|
|
6974
|
-
return resolveBorrowedRobotStatus(robotFallback);
|
|
7040
|
+
return resolveBorrowedRobotStatus(robotFallback, robotDeps);
|
|
6975
7041
|
}
|
|
6976
7042
|
const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
|
|
6977
7043
|
if ("status" in loaded) {
|
|
@@ -7013,7 +7079,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
|
|
|
7013
7079
|
}
|
|
7014
7080
|
return buildFileStatus(tokens, credentials, globalHint);
|
|
7015
7081
|
};
|
|
7016
|
-
async function resolveRobotEnforcedStatus(robotFallback) {
|
|
7082
|
+
async function resolveRobotEnforcedStatus(robotFallback, deps) {
|
|
7017
7083
|
if (isEnvAuthEnabled()) {
|
|
7018
7084
|
throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
|
|
7019
7085
|
}
|
|
@@ -7024,11 +7090,11 @@ async function resolveRobotEnforcedStatus(robotFallback) {
|
|
|
7024
7090
|
hint: `${ENFORCE_ROBOT_AUTH_VAR}=true but the UiPath Robot ` + `session is unavailable. Start and sign in to the Assistant, ` + `or unset ${ENFORCE_ROBOT_AUTH_VAR} to fall back to file or ` + `env-var authentication.`
|
|
7025
7091
|
};
|
|
7026
7092
|
}
|
|
7027
|
-
return buildRobotStatus(robotCreds);
|
|
7093
|
+
return buildRobotStatus(robotCreds, deps);
|
|
7028
7094
|
}
|
|
7029
|
-
async function resolveBorrowedRobotStatus(robotFallback) {
|
|
7095
|
+
async function resolveBorrowedRobotStatus(robotFallback, deps) {
|
|
7030
7096
|
const robotCreds = await robotFallback();
|
|
7031
|
-
return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
|
|
7097
|
+
return robotCreds ? buildRobotStatus(robotCreds, deps) : { loginStatus: "Not logged in" };
|
|
7032
7098
|
}
|
|
7033
7099
|
async function loadFileCredentials(loadEnvFile, absolutePath) {
|
|
7034
7100
|
let credentials;
|
|
@@ -7163,9 +7229,10 @@ function identityFields(accessToken, credentials) {
|
|
|
7163
7229
|
...scopes ? { scopes } : {}
|
|
7164
7230
|
};
|
|
7165
7231
|
}
|
|
7166
|
-
function buildRobotStatus(robotCreds) {
|
|
7232
|
+
async function buildRobotStatus(robotCreds, deps) {
|
|
7167
7233
|
const identity = resolveSessionIdentity(robotCreds.accessToken);
|
|
7168
7234
|
const scopes = readTokenScopes(robotCreds.accessToken);
|
|
7235
|
+
const tenant = robotCreds.tenantId ? { tenantId: robotCreds.tenantId } : await resolveRobotTenantId(robotCreds, deps);
|
|
7169
7236
|
return {
|
|
7170
7237
|
loginStatus: "Logged in",
|
|
7171
7238
|
accessToken: robotCreds.accessToken,
|
|
@@ -7173,14 +7240,62 @@ function buildRobotStatus(robotCreds) {
|
|
|
7173
7240
|
organizationName: robotCreds.organizationName,
|
|
7174
7241
|
organizationId: robotCreds.organizationId,
|
|
7175
7242
|
tenantName: robotCreds.tenantName,
|
|
7176
|
-
tenantId:
|
|
7243
|
+
tenantId: tenant.tenantId,
|
|
7177
7244
|
issuer: robotCreds.issuer,
|
|
7178
7245
|
expiration: getTokenExpiration(robotCreds.accessToken),
|
|
7179
7246
|
source: "robot" /* Robot */,
|
|
7247
|
+
...tenant.hint ? { hint: tenant.hint } : {},
|
|
7180
7248
|
...identity ? { identity } : {},
|
|
7181
7249
|
...scopes ? { scopes } : {}
|
|
7182
7250
|
};
|
|
7183
7251
|
}
|
|
7252
|
+
async function resolveRobotTenantId(robotCreds, deps) {
|
|
7253
|
+
const { baseUrl, accessToken, tenantName } = robotCreds;
|
|
7254
|
+
const organization = robotCreds.organizationName ?? robotCreds.organizationId;
|
|
7255
|
+
if (!tenantName || !organization) {
|
|
7256
|
+
return {};
|
|
7257
|
+
}
|
|
7258
|
+
const key = `${baseUrl}|${organization}|${tenantName}|${accessToken}`;
|
|
7259
|
+
let pending = deps.cache.get(key);
|
|
7260
|
+
if (!pending) {
|
|
7261
|
+
pending = catchError2(lookupRobotTenantId({ baseUrl, accessToken, organization, tenantName }, deps)).then(([error, resolution]) => {
|
|
7262
|
+
const settled = error ? { hint: tenantLookupFailureHint(tenantName, error.message) } : resolution;
|
|
7263
|
+
if (!settled.tenantId) {
|
|
7264
|
+
deps.cache.delete(key);
|
|
7265
|
+
}
|
|
7266
|
+
return settled;
|
|
7267
|
+
});
|
|
7268
|
+
deps.cache.set(key, pending);
|
|
7269
|
+
}
|
|
7270
|
+
return pending;
|
|
7271
|
+
}
|
|
7272
|
+
async function lookupRobotTenantId(target, deps) {
|
|
7273
|
+
const { baseUrl, accessToken, organization, tenantName } = target;
|
|
7274
|
+
const [error, data] = await catchError2(deps.fetchTenantsAndOrgs(baseUrl, accessToken, organization, AbortSignal.timeout(deps.lookupTimeoutMs)));
|
|
7275
|
+
if (error) {
|
|
7276
|
+
const reason = error.name === "TimeoutError" ? `the tenant list did not answer within ${deps.lookupTimeoutMs} ms.` : error.message;
|
|
7277
|
+
return { hint: tenantLookupFailureHint(tenantName, reason) };
|
|
7278
|
+
}
|
|
7279
|
+
const rows = data?.tenants;
|
|
7280
|
+
const tenants = Array.isArray(rows) ? rows.filter((tenant) => typeof tenant?.id === "string" && typeof tenant?.name === "string") : [];
|
|
7281
|
+
const wantedName = decodePathSegment(tenantName);
|
|
7282
|
+
const wanted = wantedName.toLowerCase();
|
|
7283
|
+
const match = tenants.find((tenant) => tenant.name === wantedName) ?? tenants.find((tenant) => tenant.name.toLowerCase() === wanted);
|
|
7284
|
+
if (!match) {
|
|
7285
|
+
const names = tenants.map((tenant) => tenant.name).join(", ");
|
|
7286
|
+
return {
|
|
7287
|
+
hint: `The Robot session targets tenant '${tenantName}', but ` + `organization '${organization}' lists no tenant of that name` + `${names ? ` (available: ${names})` : ""}. Commands that need ` + `the tenant id will fail until it can be resolved.`
|
|
7288
|
+
};
|
|
7289
|
+
}
|
|
7290
|
+
return { tenantId: match.id };
|
|
7291
|
+
}
|
|
7292
|
+
function tenantLookupFailureHint(tenantName, reason) {
|
|
7293
|
+
return `Could not resolve the id of tenant '${tenantName}' from the ` + `Robot session: ${reason} Commands that need the tenant id will ` + `fail until it can be resolved.`;
|
|
7294
|
+
}
|
|
7295
|
+
function decodePathSegment(segment) {
|
|
7296
|
+
const [error, decoded] = catchError2(() => decodeURIComponent(segment));
|
|
7297
|
+
return error ? segment : decoded;
|
|
7298
|
+
}
|
|
7184
7299
|
var isFileNotFoundError = (error) => {
|
|
7185
7300
|
if (!(error instanceof Object))
|
|
7186
7301
|
return false;
|
|
@@ -7416,9 +7531,6 @@ function normalizeTokenRefreshUnavailableFailure() {
|
|
|
7416
7531
|
function errorMessage(error) {
|
|
7417
7532
|
return error instanceof Error ? error.message : String(error);
|
|
7418
7533
|
}
|
|
7419
|
-
// ../auth/src/tenantSelection.ts
|
|
7420
|
-
var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
|
|
7421
|
-
|
|
7422
7534
|
// ../auth/src/selectTenant.ts
|
|
7423
7535
|
var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
|
|
7424
7536
|
var INVALID_TENANT_CODE = "INVALID_TENANT";
|
|
@@ -7538,6 +7650,68 @@ var createUiPathProviderExtension = () => {
|
|
|
7538
7650
|
};
|
|
7539
7651
|
};
|
|
7540
7652
|
|
|
7653
|
+
// src/commands/pi-output-gate.ts
|
|
7654
|
+
class PiOutputGate {
|
|
7655
|
+
saved;
|
|
7656
|
+
closed = false;
|
|
7657
|
+
open = false;
|
|
7658
|
+
constructor() {
|
|
7659
|
+
this.saved = [process.stdout, process.stderr].map((stream) => ({
|
|
7660
|
+
stream,
|
|
7661
|
+
write: stream.write,
|
|
7662
|
+
descriptor: Object.getOwnPropertyDescriptor(stream, "write")
|
|
7663
|
+
}));
|
|
7664
|
+
}
|
|
7665
|
+
close() {
|
|
7666
|
+
if (this.closed) {
|
|
7667
|
+
return;
|
|
7668
|
+
}
|
|
7669
|
+
this.closed = true;
|
|
7670
|
+
for (const { stream, write } of this.saved) {
|
|
7671
|
+
const gated = this.gate(write);
|
|
7672
|
+
Object.defineProperty(stream, "write", {
|
|
7673
|
+
configurable: true,
|
|
7674
|
+
get: () => gated,
|
|
7675
|
+
set: () => {}
|
|
7676
|
+
});
|
|
7677
|
+
}
|
|
7678
|
+
}
|
|
7679
|
+
passThrough(write) {
|
|
7680
|
+
this.open = true;
|
|
7681
|
+
try {
|
|
7682
|
+
write();
|
|
7683
|
+
} finally {
|
|
7684
|
+
this.open = false;
|
|
7685
|
+
}
|
|
7686
|
+
}
|
|
7687
|
+
restore() {
|
|
7688
|
+
if (!this.closed) {
|
|
7689
|
+
return;
|
|
7690
|
+
}
|
|
7691
|
+
this.closed = false;
|
|
7692
|
+
for (const { stream, descriptor } of this.saved) {
|
|
7693
|
+
if (descriptor) {
|
|
7694
|
+
Object.defineProperty(stream, "write", descriptor);
|
|
7695
|
+
} else {
|
|
7696
|
+
delete stream.write;
|
|
7697
|
+
}
|
|
7698
|
+
}
|
|
7699
|
+
}
|
|
7700
|
+
gate(original) {
|
|
7701
|
+
const gate = this;
|
|
7702
|
+
return function(...args) {
|
|
7703
|
+
if (gate.open) {
|
|
7704
|
+
return original.apply(this, args);
|
|
7705
|
+
}
|
|
7706
|
+
const callback = args.find((arg) => typeof arg === "function");
|
|
7707
|
+
if (callback) {
|
|
7708
|
+
queueMicrotask(callback);
|
|
7709
|
+
}
|
|
7710
|
+
return true;
|
|
7711
|
+
};
|
|
7712
|
+
}
|
|
7713
|
+
}
|
|
7714
|
+
|
|
7541
7715
|
// src/commands/chat.ts
|
|
7542
7716
|
var PI_SUBCOMMANDS = new Set([
|
|
7543
7717
|
"install",
|
|
@@ -7572,41 +7746,62 @@ function withAgentGuide(args, guideText) {
|
|
|
7572
7746
|
}
|
|
7573
7747
|
return ["--append-system-prompt", guideText, ...args];
|
|
7574
7748
|
}
|
|
7749
|
+
function toExitCode(value) {
|
|
7750
|
+
if (value === undefined || value === null) {
|
|
7751
|
+
return 0;
|
|
7752
|
+
}
|
|
7753
|
+
const code = Number(value);
|
|
7754
|
+
return Number.isInteger(code) ? code : 1;
|
|
7755
|
+
}
|
|
7756
|
+
function exitCodeSetByPi(before) {
|
|
7757
|
+
const after = process.exitCode;
|
|
7758
|
+
return after === before ? 0 : toExitCode(after);
|
|
7759
|
+
}
|
|
7575
7760
|
async function runPi(args, hardExit) {
|
|
7576
7761
|
const { main } = await import("@earendil-works/pi-coding-agent");
|
|
7577
7762
|
const originalExit = process.exit;
|
|
7763
|
+
const output = new PiOutputGate;
|
|
7764
|
+
const exitCodeBefore = process.exitCode;
|
|
7578
7765
|
let requestedExitCode;
|
|
7579
7766
|
let resolveExit = () => {};
|
|
7580
7767
|
const exitRequested = new Promise((resolve2) => {
|
|
7581
7768
|
resolveExit = resolve2;
|
|
7582
7769
|
});
|
|
7583
7770
|
process.exit = (code) => {
|
|
7584
|
-
requestedExitCode
|
|
7585
|
-
|
|
7771
|
+
if (requestedExitCode === undefined) {
|
|
7772
|
+
const exitCode = toExitCode(code ?? process.exitCode);
|
|
7773
|
+
requestedExitCode = exitCode;
|
|
7774
|
+
output.close();
|
|
7775
|
+
resolveExit(exitCode);
|
|
7776
|
+
}
|
|
7586
7777
|
return;
|
|
7587
7778
|
};
|
|
7588
7779
|
try {
|
|
7589
7780
|
const mainDone = main(args, {
|
|
7590
7781
|
extensionFactories: [createUiPathProviderExtension()]
|
|
7591
|
-
}).then(() => requestedExitCode ??
|
|
7782
|
+
}).then(() => requestedExitCode ?? exitCodeSetByPi(exitCodeBefore));
|
|
7592
7783
|
mainDone.catch(() => {});
|
|
7593
|
-
|
|
7784
|
+
const exitCode = await Promise.race([mainDone, exitRequested]);
|
|
7785
|
+
return { exitCode, output };
|
|
7594
7786
|
} finally {
|
|
7595
7787
|
process.exit = originalExit;
|
|
7596
7788
|
const exit = hardExit ?? ((code) => originalExit(code));
|
|
7597
|
-
setImmediate(() =>
|
|
7789
|
+
setImmediate(() => {
|
|
7790
|
+
output.restore();
|
|
7791
|
+
exit(toExitCode(process.exitCode ?? requestedExitCode));
|
|
7792
|
+
});
|
|
7598
7793
|
}
|
|
7599
7794
|
}
|
|
7600
7795
|
function registerChatCommand(command, context = processContext, hardExit) {
|
|
7601
7796
|
command.argument("[args...]", "arguments forwarded to the Pi coding agent (see 'uip coder --help')").allowUnknownOption().allowExcessArguments(true).helpOption(false).trackedAction(context, async (_args, _options, cmd) => {
|
|
7602
7797
|
const guide = await resolveAgentGuide();
|
|
7603
|
-
const exitCode = await runPi(withAgentGuide(cmd.args, guide), hardExit);
|
|
7798
|
+
const { exitCode, output } = await runPi(withAgentGuide(cmd.args, guide), hardExit);
|
|
7604
7799
|
if (exitCode !== 0) {
|
|
7605
|
-
OutputFormatter.error({
|
|
7800
|
+
output.passThrough(() => OutputFormatter.error({
|
|
7606
7801
|
Result: RESULTS.Failure,
|
|
7607
7802
|
Message: `The coding agent exited with code ${exitCode}.`,
|
|
7608
7803
|
Instructions: "Check the agent output above for the underlying error. Run 'uip coder --help' for usage, or 'uip login' if the uipath provider is missing."
|
|
7609
|
-
});
|
|
7804
|
+
}));
|
|
7610
7805
|
context.exit(exitCode);
|
|
7611
7806
|
}
|
|
7612
7807
|
});
|
|
@@ -7625,4 +7820,4 @@ var registerCommands = async (program2) => {
|
|
|
7625
7820
|
|
|
7626
7821
|
export { Command, setPreviewBuild, metadata, registerCommands };
|
|
7627
7822
|
|
|
7628
|
-
//# debugId=
|
|
7823
|
+
//# debugId=DA59474B0BF998E364756E2164756E21
|
package/dist/tool.js
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@uipath/coder-tool",
|
|
3
3
|
"author": "UiPath",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.205.0-preview.256",
|
|
6
6
|
"description": "Interactive coding agent (Pi) with UiPath LLM Gateway and BYO provider support.",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@earendil-works/pi-coding-agent": "^0.80.6"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "63740c6cbb7ff282fa9118cc16a148eb030b245f"
|
|
25
25
|
}
|