@uipath/uipath-extensions-sdk 0.1.21 → 0.1.23
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 +64 -14
- package/dist/adopt.d.ts +6 -0
- package/dist/adopt.js +462 -101
- package/dist/adopt.js.map +1 -1
- package/dist/cli.js +42 -7
- package/dist/cli.js.map +1 -1
- package/dist/commands/build-check.d.ts +2 -2
- package/dist/commands/build-check.js +43 -18
- package/dist/commands/build-check.js.map +1 -1
- package/dist/commands/new.d.ts +1 -0
- package/dist/commands/new.js +44 -2
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/pack.d.ts +12 -0
- package/dist/commands/pack.js +96 -30
- package/dist/commands/pack.js.map +1 -1
- package/dist/commands/submit.d.ts +41 -1
- package/dist/commands/submit.js +484 -23
- package/dist/commands/submit.js.map +1 -1
- package/dist/commands/upload.d.ts +4 -0
- package/dist/commands/upload.js +98 -26
- package/dist/commands/upload.js.map +1 -1
- package/dist/commands/validate-python.d.ts +15 -0
- package/dist/commands/validate-python.js +334 -0
- package/dist/commands/validate-python.js.map +1 -0
- package/dist/commands/validate.js +2 -1
- package/dist/commands/validate.js.map +1 -1
- package/dist/connector.d.ts +23 -0
- package/dist/connector.js +258 -0
- package/dist/connector.js.map +1 -0
- package/dist/github.d.ts +6 -0
- package/dist/github.js +12 -0
- package/dist/github.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +4 -1
- package/dist/lib.js +307 -27
- package/dist/lib.js.map +1 -1
- package/dist/pyproject.d.ts +1 -0
- package/dist/pyproject.js +16 -0
- package/dist/pyproject.js.map +1 -0
- package/dist/python-source.d.ts +25 -0
- package/dist/python-source.js +359 -0
- package/dist/python-source.js.map +1 -0
- package/dist/registrationFile.d.ts +10 -0
- package/dist/registrationFile.js +51 -1
- package/dist/registrationFile.js.map +1 -1
- package/dist/sourceWalk.d.ts +2 -1
- package/dist/sourceWalk.js +5 -3
- package/dist/sourceWalk.js.map +1 -1
- package/dist/symlinkProblem.d.ts +1 -0
- package/dist/symlinkProblem.js +25 -0
- package/dist/symlinkProblem.js.map +1 -0
- package/dist/verdict.d.ts +6 -0
- package/dist/verdict.js +13 -0
- package/dist/verdict.js.map +1 -0
- package/package.json +6 -2
package/dist/adopt.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { assetsProblem, CONNECTION_HELPER_PATH, CONNECTION_HELPER_SOURCE, connectionInputNames, FIXTURES_DIR, fixtureProblem, ICON_PATH, ICON_PATH_PATTERN, iconPathOf, isAllowedSourceDir, isAllowedSourcePath, isLocalOnlySource, MANIFEST_FILE, PackedArchiveError, PYPROJECT, packageNameProblem, packedName, parsePacked, parseTomlText, readPackedEntries, readTomlFile, templateProblems, UV_LOCK, } from "@uipath/uipath-extensions-gates";
|
|
4
5
|
import { strFromU8 } from "fflate";
|
|
5
6
|
import { parse } from "yaml";
|
|
6
7
|
import { labelOf, TYPES_NODE_PACKAGE, TYPES_NODE_VERSION, } from "./commands/new.js";
|
|
7
|
-
import { PackError,
|
|
8
|
+
import { PACK_TIMEOUT_MS, PackError, projectKind, runUipPack, tail, } from "./commands/pack.js";
|
|
8
9
|
import { DEFAULT_INDEX_REPO } from "./commands/submit.js";
|
|
9
10
|
import { DEFAULT_ICON_BASE64 } from "./defaultIcon.js";
|
|
10
11
|
import { exists } from "./exists.js";
|
|
11
12
|
import { FIXTURE_PATH, starterFixtureText } from "./fixture.js";
|
|
12
13
|
import { GitHubError, ghClient } from "./github.js";
|
|
14
|
+
import { setProjectField } from "./pyproject.js";
|
|
15
|
+
import { checkPythonAdoptFiles, isPythonFunctionProject, isPythonFunctionVersion, PythonFunctionError, packConfig, pythonFunctions, validPythonFunctionTarget, } from "./python-source.js";
|
|
13
16
|
import { REGISTRATION_FILE } from "./registrationFile.js";
|
|
14
17
|
import { excludedNames, isSkippedEntry, offListRemedy, walkSources, } from "./sourceWalk.js";
|
|
18
|
+
import { symlinkProblem } from "./symlinkProblem.js";
|
|
15
19
|
import { UipMissingError } from "./uip.js";
|
|
16
|
-
const PACK_TIMEOUT_MS = 600_000;
|
|
17
|
-
const MAX_OUTPUT_CHARS = 2000;
|
|
18
20
|
const POLICY_FILE = "policy/gate-library.yaml";
|
|
19
21
|
const SCHEMA_KEY = "template_schema";
|
|
20
22
|
export const NAME_PREFIX = "uipath-extensions.";
|
|
@@ -68,7 +70,6 @@ const jsonWriter = (text) => {
|
|
|
68
70
|
const newline = text.endsWith("\n") ? "\n" : "";
|
|
69
71
|
return (value) => `${JSON.stringify(value, null, indent)}${newline}`;
|
|
70
72
|
};
|
|
71
|
-
const tail = (text) => text.length > MAX_OUTPUT_CHARS ? `...${text.slice(-MAX_OUTPUT_CHARS)}` : text;
|
|
72
73
|
async function readText(path) {
|
|
73
74
|
try {
|
|
74
75
|
return await readFile(path, "utf8");
|
|
@@ -77,6 +78,26 @@ async function readText(path) {
|
|
|
77
78
|
return undefined;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
81
|
+
// A lossy read is unsafe when init may write back the same file.
|
|
82
|
+
async function readPythonText(dir, file) {
|
|
83
|
+
let bytes;
|
|
84
|
+
try {
|
|
85
|
+
bytes = await readFile(join(dir, file));
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return error.code === "ENOENT"
|
|
89
|
+
? { text: undefined }
|
|
90
|
+
: { error: `${file}: file not readable` };
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
return {
|
|
94
|
+
text: new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return { error: `${file} must be valid UTF-8` };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
80
101
|
function parseJson(text) {
|
|
81
102
|
try {
|
|
82
103
|
return JSON.parse(text);
|
|
@@ -104,31 +125,58 @@ function templateOperation(text) {
|
|
|
104
125
|
? first.name
|
|
105
126
|
: undefined;
|
|
106
127
|
}
|
|
107
|
-
async function outsideSourceList(root, excluded) {
|
|
128
|
+
async function outsideSourceList(root, excluded, kind = "function") {
|
|
108
129
|
const found = [];
|
|
130
|
+
const listed = [];
|
|
109
131
|
await walkSources(root, async (entry, path, dir) => {
|
|
110
|
-
if (isSkippedEntry(entry, dir, excluded) ||
|
|
111
|
-
(dir === "" && isLocalOnlySource(entry.name)) ||
|
|
132
|
+
if (isSkippedEntry(entry, dir, excluded, kind) ||
|
|
133
|
+
(dir === "" && isLocalOnlySource(entry.name, kind)) ||
|
|
112
134
|
(dir === "" && entry.isFile() && entry.name === REGISTRATION_FILE)) {
|
|
113
135
|
return false;
|
|
114
136
|
}
|
|
115
137
|
if (entry.isDirectory()) {
|
|
116
|
-
if (dir === "" && !isAllowedSourceDir(entry.name)) {
|
|
138
|
+
if (dir === "" && !isAllowedSourceDir(entry.name, kind)) {
|
|
117
139
|
found.push(`${path}/`);
|
|
118
140
|
return false;
|
|
119
141
|
}
|
|
120
142
|
return true;
|
|
121
143
|
}
|
|
122
|
-
if (!entry.isFile() || !isAllowedSourcePath(path))
|
|
144
|
+
if (!entry.isFile() || !isAllowedSourcePath(path, kind)) {
|
|
123
145
|
found.push(path);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
listed.push(path);
|
|
149
|
+
}
|
|
124
150
|
return false;
|
|
125
151
|
});
|
|
126
|
-
return found;
|
|
152
|
+
return { found, listed };
|
|
153
|
+
}
|
|
154
|
+
async function planSourceReports(plan, dir, excluded, kind = "function") {
|
|
155
|
+
const { found, listed } = await outsideSourceList(dir, excluded, kind);
|
|
156
|
+
for (const path of found) {
|
|
157
|
+
plan.reports.push({
|
|
158
|
+
path,
|
|
159
|
+
problem: `is not on the source list, ${offListRemedy(path)}`,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
const assets = assetsProblem([
|
|
163
|
+
...listed,
|
|
164
|
+
...plan.writes.map((write) => write.path),
|
|
165
|
+
]);
|
|
166
|
+
if (assets !== undefined) {
|
|
167
|
+
plan.reports.push({ path: "assets/", problem: `is refused, ${assets}` });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function templateIconPath(manifestText) {
|
|
171
|
+
const template = manifestText === undefined ? undefined : parseJson(manifestText);
|
|
172
|
+
const display = isRecord(template) ? template.display : undefined;
|
|
173
|
+
const icon = iconPathOf(isRecord(display) ? display : undefined);
|
|
174
|
+
return ICON_PATH_PATTERN.test(icon) ? icon : ICON_PATH;
|
|
127
175
|
}
|
|
128
|
-
async function junkNames(root, excluded) {
|
|
176
|
+
async function junkNames(root, excluded, kind = "function") {
|
|
129
177
|
const found = new Set();
|
|
130
178
|
await walkSources(root, async (entry, _path, dir) => {
|
|
131
|
-
if (isSkippedEntry(entry, dir, excluded))
|
|
179
|
+
if (isSkippedEntry(entry, dir, excluded, kind))
|
|
132
180
|
return false;
|
|
133
181
|
const key = entry.isDirectory()
|
|
134
182
|
? "directoriesExcluded"
|
|
@@ -137,7 +185,8 @@ async function junkNames(root, excluded) {
|
|
|
137
185
|
found.add(entry.name);
|
|
138
186
|
return false;
|
|
139
187
|
}
|
|
140
|
-
return (entry.isDirectory() &&
|
|
188
|
+
return (entry.isDirectory() &&
|
|
189
|
+
(dir !== "" || isAllowedSourceDir(entry.name, kind)));
|
|
141
190
|
});
|
|
142
191
|
const keys = Object.keys(JUNK);
|
|
143
192
|
return keys
|
|
@@ -273,36 +322,22 @@ function operationName(filePath) {
|
|
|
273
322
|
return /^[A-Za-z]/.test(name) ? name : "run";
|
|
274
323
|
}
|
|
275
324
|
async function runPack(deps, dir, nupkgName) {
|
|
276
|
-
let result;
|
|
277
325
|
try {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
326
|
+
return {
|
|
327
|
+
nupkg: await runUipPack({
|
|
328
|
+
projectDir: dir,
|
|
329
|
+
exec: deps.exec,
|
|
330
|
+
command: "uip function pack",
|
|
331
|
+
nupkgName,
|
|
332
|
+
}),
|
|
333
|
+
};
|
|
282
334
|
}
|
|
283
335
|
catch (error) {
|
|
284
|
-
if (error instanceof PackError)
|
|
336
|
+
if (error instanceof PackError || error instanceof UipMissingError) {
|
|
285
337
|
return { error: error.message };
|
|
286
|
-
if (error.code === "ENOENT") {
|
|
287
|
-
return { error: new UipMissingError().message };
|
|
288
338
|
}
|
|
289
339
|
throw error;
|
|
290
340
|
}
|
|
291
|
-
if (result.timedOut)
|
|
292
|
-
return { error: "uip function pack timed out" };
|
|
293
|
-
if (result.code !== 0) {
|
|
294
|
-
return {
|
|
295
|
-
error: `uip function pack exited with code ${result.code}: ${tail(result.stderr || result.stdout)}`,
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
for (const where of [".uipath", ""]) {
|
|
299
|
-
const candidate = join(dir, where, nupkgName);
|
|
300
|
-
if (await exists(candidate))
|
|
301
|
-
return { nupkg: candidate };
|
|
302
|
-
}
|
|
303
|
-
return {
|
|
304
|
-
error: `uip function pack finished but ${nupkgName} was not created in the project or in .uipath`,
|
|
305
|
-
};
|
|
306
341
|
}
|
|
307
342
|
function runtimeProblems(entries) {
|
|
308
343
|
const bytes = entries[packedName(entries, "operate.json")];
|
|
@@ -330,8 +365,370 @@ function undescribedInputs(input) {
|
|
|
330
365
|
property.description.trim() === "")
|
|
331
366
|
.map(([name]) => name);
|
|
332
367
|
}
|
|
368
|
+
export { isPythonFunctionProject } from "./python-source.js";
|
|
369
|
+
export async function pythonFunctionNeedsId(dir) {
|
|
370
|
+
if (!(await isPythonFunctionProject(dir)))
|
|
371
|
+
return false;
|
|
372
|
+
const result = await readTomlFile(join(dir, PYPROJECT));
|
|
373
|
+
const project = "value" in result && result.value.project;
|
|
374
|
+
return isRecord(project) && packageNameProblem(project.name) !== undefined;
|
|
375
|
+
}
|
|
376
|
+
function replaceProjectName(text, name) {
|
|
377
|
+
const lines = text.split("\n");
|
|
378
|
+
let inProject = false;
|
|
379
|
+
let changed = false;
|
|
380
|
+
for (const [i, line] of lines.entries()) {
|
|
381
|
+
if (/^\s*\[/.test(line)) {
|
|
382
|
+
inProject = /^\s*\[project\]\s*(?:#.*)?$/.test(line);
|
|
383
|
+
}
|
|
384
|
+
if (!inProject)
|
|
385
|
+
continue;
|
|
386
|
+
const match = /^(\s*name\s*=\s*)(?:"[^"\\]*"|'[^']*')(\s*(?:#.*)?)$/.exec(line);
|
|
387
|
+
if (!match)
|
|
388
|
+
continue;
|
|
389
|
+
if (changed)
|
|
390
|
+
return undefined;
|
|
391
|
+
lines[i] = `${match[1]}"${name}"${match[2]}`;
|
|
392
|
+
changed = true;
|
|
393
|
+
}
|
|
394
|
+
return changed ? lines.join("\n") : undefined;
|
|
395
|
+
}
|
|
396
|
+
async function planPythonFunction(opts, deps, uipath, uipathText, functions) {
|
|
397
|
+
const plan = { writes: [], reports: [], errors: [] };
|
|
398
|
+
const fail = (message) => ({
|
|
399
|
+
writes: [],
|
|
400
|
+
reports: [],
|
|
401
|
+
errors: [...plan.errors, message],
|
|
402
|
+
});
|
|
403
|
+
const entries = Object.entries(functions);
|
|
404
|
+
if (entries.length !== 1)
|
|
405
|
+
return fail("a node holds one function");
|
|
406
|
+
const [main, target] = entries[0];
|
|
407
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(main) ||
|
|
408
|
+
!validPythonFunctionTarget(target)) {
|
|
409
|
+
return fail("uipath.json must map a function name to a Python source file and function");
|
|
410
|
+
}
|
|
411
|
+
const projectText = await readPythonText(opts.dir, PYPROJECT);
|
|
412
|
+
if ("error" in projectText)
|
|
413
|
+
return fail(projectText.error);
|
|
414
|
+
const before = projectText.text;
|
|
415
|
+
if (before === undefined)
|
|
416
|
+
return fail(`${PYPROJECT}: file not readable`);
|
|
417
|
+
const parsed = parseTomlText(before);
|
|
418
|
+
if ("error" in parsed)
|
|
419
|
+
return fail(`${PYPROJECT}: ${parsed.error}`);
|
|
420
|
+
const project = parsed.value.project;
|
|
421
|
+
if (!isRecord(project) ||
|
|
422
|
+
typeof project.name !== "string" ||
|
|
423
|
+
typeof project.version !== "string") {
|
|
424
|
+
return fail(`${PYPROJECT} must have a [project] name and version`);
|
|
425
|
+
}
|
|
426
|
+
if (!isPythonFunctionVersion(project.version))
|
|
427
|
+
return fail(`${PYPROJECT} needs a plain x.y.z package version`);
|
|
428
|
+
const iconExclusion = [...ICON_NAMES, ICON_PATH].find((entry) => excludedNames(uipath).has(entry));
|
|
429
|
+
if (iconExclusion !== undefined)
|
|
430
|
+
return fail(iconExcludedProblem(iconExclusion));
|
|
431
|
+
let hasIcon;
|
|
432
|
+
try {
|
|
433
|
+
packConfig(uipath);
|
|
434
|
+
hasIcon = await checkPythonAdoptFiles(opts.dir, target.split(":")[0]);
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
if (error instanceof PythonFunctionError)
|
|
438
|
+
return fail(error.message);
|
|
439
|
+
throw error;
|
|
440
|
+
}
|
|
441
|
+
let name = project.name;
|
|
442
|
+
if (packageNameProblem(name)) {
|
|
443
|
+
if (opts.id === undefined)
|
|
444
|
+
return fail(MISSING_ID_ERROR);
|
|
445
|
+
name = `${NAME_PREFIX}${opts.id}`;
|
|
446
|
+
const problem = packageNameProblem(name);
|
|
447
|
+
if (problem !== undefined)
|
|
448
|
+
return fail(problem.replace("package.json name", "pyproject.toml [project].name"));
|
|
449
|
+
const after = replaceProjectName(before, name);
|
|
450
|
+
if (after === undefined) {
|
|
451
|
+
return fail('place the project name on one standalone name = "..." line in [project]');
|
|
452
|
+
}
|
|
453
|
+
const updated = parseTomlText(after);
|
|
454
|
+
const nextProject = "value" in updated ? updated.value.project : undefined;
|
|
455
|
+
if ("error" in updated ||
|
|
456
|
+
!isRecord(nextProject) ||
|
|
457
|
+
!isDeepStrictEqual({ ...updated.value, project: { ...nextProject } }, { ...parsed.value, project: { ...project, name } })) {
|
|
458
|
+
return fail(`renaming the package would change another field in ${PYPROJECT}`);
|
|
459
|
+
}
|
|
460
|
+
plan.writes.push({ path: PYPROJECT, before, after, identity: true });
|
|
461
|
+
if (await exists(join(opts.dir, "uv.lock"))) {
|
|
462
|
+
plan.reports.push({
|
|
463
|
+
path: "uv.lock",
|
|
464
|
+
problem: "run uv lock after the Python project is renamed",
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
const existingManifest = await readPythonText(opts.dir, MANIFEST_FILE);
|
|
469
|
+
if ("error" in existingManifest)
|
|
470
|
+
return fail(existingManifest.error);
|
|
471
|
+
const manifestText = existingManifest.text;
|
|
472
|
+
if (manifestText === undefined) {
|
|
473
|
+
if (project.license !== undefined &&
|
|
474
|
+
(typeof project.license !== "string" || project.license.trim() === "")) {
|
|
475
|
+
return fail(`${PYPROJECT} [project].license must be an SPDX string before generating the extension manifest; initialize with an explicit license instead of replacing the existing declaration`);
|
|
476
|
+
}
|
|
477
|
+
const found = opts.offline
|
|
478
|
+
? { schema: 2 }
|
|
479
|
+
: await templateSchema(deps, opts.index ?? DEFAULT_INDEX_REPO);
|
|
480
|
+
if ("error" in found)
|
|
481
|
+
return fail(found.error);
|
|
482
|
+
const template = newTemplate(found.schema, project.version, name, operationName(main), hasIcon ? "own" : "default", typeof project.license === "string" ? project.license : undefined);
|
|
483
|
+
plan.writes.push({
|
|
484
|
+
path: MANIFEST_FILE,
|
|
485
|
+
before: null,
|
|
486
|
+
after: template.text,
|
|
487
|
+
});
|
|
488
|
+
plan.generated = template.generated;
|
|
489
|
+
if (!hasIcon)
|
|
490
|
+
plan.writes.push(defaultIconWrite());
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
planExistingTemplateIcon(plan, {
|
|
494
|
+
text: manifestText,
|
|
495
|
+
hasIcon,
|
|
496
|
+
iconExclusion,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
const plannedManifest = plan.writes.find(({ path }) => path === MANIFEST_FILE)?.after ??
|
|
500
|
+
manifestText;
|
|
501
|
+
const parsedManifest = plannedManifest === undefined ? undefined : parseJson(plannedManifest);
|
|
502
|
+
const problems = templateProblems(parsedManifest);
|
|
503
|
+
if (problems.length > 0)
|
|
504
|
+
return fail(`invalid ${MANIFEST_FILE}: ${problems.join("; ")}`);
|
|
505
|
+
const display = isRecord(parsedManifest) ? parsedManifest.display : undefined;
|
|
506
|
+
if (isRecord(display) && display.icon === ICON_PATH) {
|
|
507
|
+
const options = uipath.packOptions;
|
|
508
|
+
if (options !== undefined && !isRecord(options)) {
|
|
509
|
+
return fail("uipath.json packOptions must be an object");
|
|
510
|
+
}
|
|
511
|
+
const files = options?.filesIncluded ?? [];
|
|
512
|
+
if (!Array.isArray(files) ||
|
|
513
|
+
!files.every((entry) => typeof entry === "string")) {
|
|
514
|
+
return fail("uipath.json packOptions.filesIncluded must be a list of filenames");
|
|
515
|
+
}
|
|
516
|
+
if (!files.includes(ICON_PATH)) {
|
|
517
|
+
plan.writes.push({
|
|
518
|
+
path: "uipath.json",
|
|
519
|
+
before: uipathText,
|
|
520
|
+
after: jsonWriter(uipathText)({
|
|
521
|
+
...uipath,
|
|
522
|
+
packOptions: { ...options, filesIncluded: [...files, ICON_PATH] },
|
|
523
|
+
}),
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
for (const { path } of plan.writes) {
|
|
528
|
+
const problem = await symlinkProblem(opts.dir, path, "adopt");
|
|
529
|
+
if (problem !== undefined)
|
|
530
|
+
plan.errors.push(problem);
|
|
531
|
+
}
|
|
532
|
+
return plan;
|
|
533
|
+
}
|
|
534
|
+
async function planTemplate(plan, opts, deps, node) {
|
|
535
|
+
const { manifestText, hasIcon, iconExclusion } = node;
|
|
536
|
+
if (manifestText !== undefined) {
|
|
537
|
+
planExistingTemplateIcon(plan, {
|
|
538
|
+
text: manifestText,
|
|
539
|
+
hasIcon,
|
|
540
|
+
iconExclusion,
|
|
541
|
+
});
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const found = opts.offline
|
|
545
|
+
? { schema: 2 }
|
|
546
|
+
: await templateSchema(deps, opts.index ?? DEFAULT_INDEX_REPO);
|
|
547
|
+
if ("error" in found) {
|
|
548
|
+
plan.errors.push(found.error);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const skipIcon = iconExclusion !== undefined && found.schema === undefined;
|
|
552
|
+
if (iconExclusion !== undefined && !skipIcon) {
|
|
553
|
+
plan.errors.push(iconExcludedProblem(iconExclusion));
|
|
554
|
+
}
|
|
555
|
+
const template = newTemplate(found.schema, node.version, node.packageName, node.operation, skipIcon ? "none" : hasIcon ? "own" : "default", node.license);
|
|
556
|
+
plan.writes.push({
|
|
557
|
+
path: MANIFEST_FILE,
|
|
558
|
+
before: null,
|
|
559
|
+
after: template.text,
|
|
560
|
+
});
|
|
561
|
+
plan.generated = template.generated;
|
|
562
|
+
if (!hasIcon && !skipIcon)
|
|
563
|
+
plan.writes.push(defaultIconWrite());
|
|
564
|
+
}
|
|
565
|
+
const AGENT_OPERATION = "run";
|
|
566
|
+
const ENTRY_POINTS_FILE = "entry-points.json";
|
|
567
|
+
export const AGENT_INIT = "uipath.json and entry-points.json are missing. Run init, which runs uip codedagent init to write them";
|
|
568
|
+
export const AGENT_LOCK = `${UV_LOCK} is missing. Run init, which runs uv lock to write it`;
|
|
569
|
+
const missing = async (dir, name) => (await readText(join(dir, name))) === undefined;
|
|
570
|
+
const needsCodedAgentInit = async (dir) => (await missing(dir, "uipath.json")) ||
|
|
571
|
+
(await missing(dir, ENTRY_POINTS_FILE));
|
|
572
|
+
export async function needsAgentInit(dir) {
|
|
573
|
+
return ((await projectKind(dir)) === "agent" &&
|
|
574
|
+
((await needsCodedAgentInit(dir)) || (await missing(dir, UV_LOCK))));
|
|
575
|
+
}
|
|
576
|
+
async function runStep(exec, dir, command, args) {
|
|
577
|
+
const name = [command, ...args].join(" ");
|
|
578
|
+
let result;
|
|
579
|
+
try {
|
|
580
|
+
result = await exec(command, args, { cwd: dir, timeout: PACK_TIMEOUT_MS });
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
if (error.code === "ENOENT") {
|
|
584
|
+
return command === "uip"
|
|
585
|
+
? new UipMissingError().message
|
|
586
|
+
: `${command} was not found on the PATH. Install it, then run this command again.`;
|
|
587
|
+
}
|
|
588
|
+
throw error;
|
|
589
|
+
}
|
|
590
|
+
if (result.timedOut)
|
|
591
|
+
return `${name} timed out`;
|
|
592
|
+
return result.code === 0
|
|
593
|
+
? undefined
|
|
594
|
+
: `${name} exited with code ${result.code}: ${tail(result.stderr || result.stdout)}`;
|
|
595
|
+
}
|
|
596
|
+
export async function runAgentInit(dir, exec) {
|
|
597
|
+
if (await needsCodedAgentInit(dir)) {
|
|
598
|
+
const failure = await runStep(exec, dir, "uip", ["codedagent", "init"]);
|
|
599
|
+
if (failure !== undefined)
|
|
600
|
+
return failure;
|
|
601
|
+
if (await needsCodedAgentInit(dir)) {
|
|
602
|
+
return "uip codedagent init finished but did not write uipath.json and entry-points.json";
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
if (await missing(dir, UV_LOCK)) {
|
|
606
|
+
const failure = await runStep(exec, dir, "uv", ["lock"]);
|
|
607
|
+
if (failure !== undefined)
|
|
608
|
+
return failure;
|
|
609
|
+
if (await missing(dir, UV_LOCK)) {
|
|
610
|
+
return `uv lock finished but did not write ${UV_LOCK}`;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return undefined;
|
|
614
|
+
}
|
|
615
|
+
function agentPackOptions(text, uipath, packsIcon, iconPath) {
|
|
616
|
+
const options = uipath.packOptions === undefined ? {} : uipath.packOptions;
|
|
617
|
+
if (!isRecord(options)) {
|
|
618
|
+
return { error: "uipath.json packOptions is not an object" };
|
|
619
|
+
}
|
|
620
|
+
const included = options.filesIncluded === undefined ? [] : options.filesIncluded;
|
|
621
|
+
if (!Array.isArray(included)) {
|
|
622
|
+
return { error: "uipath.json packOptions.filesIncluded is not a list" };
|
|
623
|
+
}
|
|
624
|
+
const listsIcon = !packsIcon || included.includes(iconPath);
|
|
625
|
+
if (listsIcon && options.includeUvLock === true)
|
|
626
|
+
return {};
|
|
627
|
+
return {
|
|
628
|
+
write: {
|
|
629
|
+
path: "uipath.json",
|
|
630
|
+
before: text,
|
|
631
|
+
after: jsonWriter(text)({
|
|
632
|
+
...uipath,
|
|
633
|
+
packOptions: {
|
|
634
|
+
...options,
|
|
635
|
+
...(!listsIcon && { filesIncluded: [...included, iconPath] }),
|
|
636
|
+
includeUvLock: true,
|
|
637
|
+
},
|
|
638
|
+
}),
|
|
639
|
+
},
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
async function planAgentAdopt(opts, deps, plan) {
|
|
643
|
+
const fail = (message) => {
|
|
644
|
+
plan.errors.push(message);
|
|
645
|
+
return plan;
|
|
646
|
+
};
|
|
647
|
+
const uipathText = await readText(join(opts.dir, "uipath.json"));
|
|
648
|
+
const entryText = await readText(join(opts.dir, ENTRY_POINTS_FILE));
|
|
649
|
+
if (uipathText === undefined || entryText === undefined) {
|
|
650
|
+
return fail(AGENT_INIT);
|
|
651
|
+
}
|
|
652
|
+
if (await missing(opts.dir, UV_LOCK))
|
|
653
|
+
return fail(AGENT_LOCK);
|
|
654
|
+
const uipath = parseJson(uipathText);
|
|
655
|
+
if (!isRecord(uipath))
|
|
656
|
+
return fail("uipath.json is not a valid JSON object");
|
|
657
|
+
const entry = parseJson(entryText);
|
|
658
|
+
const entryPoints = isRecord(entry) ? entry.entryPoints : undefined;
|
|
659
|
+
if (!Array.isArray(entryPoints) || entryPoints.length !== 1) {
|
|
660
|
+
return fail(`${ENTRY_POINTS_FILE} must list one entry point, a node holds one agent`);
|
|
661
|
+
}
|
|
662
|
+
const pyprojectText = await readText(join(opts.dir, PYPROJECT));
|
|
663
|
+
const toml = await readTomlFile(join(opts.dir, PYPROJECT));
|
|
664
|
+
if (pyprojectText === undefined || "error" in toml) {
|
|
665
|
+
return fail(`${PYPROJECT}: ${"error" in toml ? toml.error : "file not found"}`);
|
|
666
|
+
}
|
|
667
|
+
const { project } = toml.value;
|
|
668
|
+
if (!isRecord(project) || typeof project.version !== "string") {
|
|
669
|
+
return fail(`${PYPROJECT} needs a [project] table with a version`);
|
|
670
|
+
}
|
|
671
|
+
let packageName = String(project.name);
|
|
672
|
+
if (packageNameProblem(project.name) !== undefined) {
|
|
673
|
+
if (opts.id === undefined) {
|
|
674
|
+
plan.errors.push(MISSING_ID_ERROR);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
const name = `${NAME_PREFIX}${opts.id}`;
|
|
678
|
+
const problem = packageNameProblem(name);
|
|
679
|
+
const after = problem === undefined
|
|
680
|
+
? setProjectField(pyprojectText, "name", name)
|
|
681
|
+
: undefined;
|
|
682
|
+
if (problem !== undefined) {
|
|
683
|
+
plan.errors.push(problem);
|
|
684
|
+
}
|
|
685
|
+
else if (after === undefined) {
|
|
686
|
+
plan.errors.push(`${PYPROJECT} has no [project] name line to set`);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
packageName = name;
|
|
690
|
+
plan.writes.push({
|
|
691
|
+
path: PYPROJECT,
|
|
692
|
+
before: pyprojectText,
|
|
693
|
+
after,
|
|
694
|
+
identity: true,
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const manifestText = await readText(join(opts.dir, MANIFEST_FILE));
|
|
700
|
+
const iconPath = templateIconPath(manifestText);
|
|
701
|
+
const hasIcon = await exists(join(opts.dir, iconPath));
|
|
702
|
+
const excluded = excludedNames(uipath);
|
|
703
|
+
await planTemplate(plan, opts, deps, {
|
|
704
|
+
manifestText,
|
|
705
|
+
version: project.version,
|
|
706
|
+
packageName,
|
|
707
|
+
operation: templateOperation(manifestText) ?? AGENT_OPERATION,
|
|
708
|
+
hasIcon,
|
|
709
|
+
iconExclusion: iconPath.split("/").find((name) => excluded.has(name)),
|
|
710
|
+
license: undefined,
|
|
711
|
+
});
|
|
712
|
+
const packOptions = agentPackOptions(uipathText, uipath, hasIcon || plan.writes.some((write) => write.path === ICON_PATH), iconPath);
|
|
713
|
+
if ("error" in packOptions) {
|
|
714
|
+
plan.errors.push(packOptions.error);
|
|
715
|
+
}
|
|
716
|
+
else if (packOptions.write) {
|
|
717
|
+
plan.writes.push(packOptions.write);
|
|
718
|
+
}
|
|
719
|
+
await planSourceReports(plan, opts.dir, excluded, "agent");
|
|
720
|
+
for (const { path } of plan.writes) {
|
|
721
|
+
const problem = await symlinkProblem(opts.dir, path, "adopt");
|
|
722
|
+
if (problem !== undefined)
|
|
723
|
+
plan.errors.push(problem);
|
|
724
|
+
}
|
|
725
|
+
return plan;
|
|
726
|
+
}
|
|
333
727
|
export async function planAdopt(opts, deps) {
|
|
334
728
|
const plan = { writes: [], reports: [], errors: [] };
|
|
729
|
+
if ((await projectKind(opts.dir)) === "agent") {
|
|
730
|
+
return planAgentAdopt(opts, deps, plan);
|
|
731
|
+
}
|
|
335
732
|
const fail = (message) => {
|
|
336
733
|
plan.errors.push(message);
|
|
337
734
|
return plan;
|
|
@@ -344,8 +741,18 @@ export async function planAdopt(opts, deps) {
|
|
|
344
741
|
if (!isRecord(uipath))
|
|
345
742
|
return fail("uipath.json is not a valid JSON object");
|
|
346
743
|
const packageText = await readText(join(opts.dir, "package.json"));
|
|
347
|
-
if (packageText === undefined)
|
|
744
|
+
if (packageText === undefined) {
|
|
745
|
+
const functions = pythonFunctions(uipath);
|
|
746
|
+
if (functions !== undefined && (await isPythonFunctionProject(opts.dir))) {
|
|
747
|
+
const exact = await readPythonText(opts.dir, "uipath.json");
|
|
748
|
+
if ("error" in exact)
|
|
749
|
+
return fail(exact.error);
|
|
750
|
+
if (exact.text !== uipathText)
|
|
751
|
+
return fail("uipath.json changed while planning, run again");
|
|
752
|
+
return planPythonFunction(opts, deps, uipath, uipathText, functions);
|
|
753
|
+
}
|
|
348
754
|
return fail("package.json not found");
|
|
755
|
+
}
|
|
349
756
|
const pkg = parseJson(packageText);
|
|
350
757
|
if (!isRecord(pkg))
|
|
351
758
|
return fail("package.json is not a valid JSON object");
|
|
@@ -401,36 +808,15 @@ export async function planAdopt(opts, deps) {
|
|
|
401
808
|
const iconExclusion = ICON_NAMES.find((name) => excluded.has(name));
|
|
402
809
|
const manifestText = await readText(join(opts.dir, MANIFEST_FILE));
|
|
403
810
|
const operation = templateOperation(manifestText) ?? operationName(entry.filePath);
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (iconExclusion !== undefined && !skipIcon) {
|
|
414
|
-
plan.errors.push(iconExcludedProblem(iconExclusion));
|
|
415
|
-
}
|
|
416
|
-
const template = newTemplate(found.schema, pkg.version, String(nextPkg.name), operation, skipIcon ? "none" : hasIcon ? "own" : "default", pkg.license);
|
|
417
|
-
plan.writes.push({
|
|
418
|
-
path: MANIFEST_FILE,
|
|
419
|
-
before: null,
|
|
420
|
-
after: template.text,
|
|
421
|
-
});
|
|
422
|
-
plan.generated = template.generated;
|
|
423
|
-
if (!hasIcon && !skipIcon)
|
|
424
|
-
plan.writes.push(defaultIconWrite());
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
planExistingTemplateIcon(plan, {
|
|
429
|
-
text: manifestText,
|
|
430
|
-
hasIcon,
|
|
431
|
-
iconExclusion,
|
|
432
|
-
});
|
|
433
|
-
}
|
|
811
|
+
await planTemplate(plan, opts, deps, {
|
|
812
|
+
manifestText,
|
|
813
|
+
version: pkg.version,
|
|
814
|
+
packageName: String(nextPkg.name),
|
|
815
|
+
operation,
|
|
816
|
+
hasIcon,
|
|
817
|
+
iconExclusion,
|
|
818
|
+
license: pkg.license,
|
|
819
|
+
});
|
|
434
820
|
if ((await fixtureProblem(opts.dir)) !== undefined) {
|
|
435
821
|
const blocked = await starterFixtureBlocked(opts.dir);
|
|
436
822
|
if (blocked !== undefined) {
|
|
@@ -494,12 +880,7 @@ export async function planAdopt(opts, deps) {
|
|
|
494
880
|
skipped = new Set([...excluded, ...junk.flatMap(([, names]) => names)]);
|
|
495
881
|
}
|
|
496
882
|
}
|
|
497
|
-
|
|
498
|
-
plan.reports.push({
|
|
499
|
-
path,
|
|
500
|
-
problem: `is not on the source list, ${offListRemedy(path)}`,
|
|
501
|
-
});
|
|
502
|
-
}
|
|
883
|
+
await planSourceReports(plan, opts.dir, skipped);
|
|
503
884
|
for (const name of undescribedInputs(entry.input)) {
|
|
504
885
|
plan.reports.push({
|
|
505
886
|
path: "entry-points.json",
|
|
@@ -507,44 +888,24 @@ export async function planAdopt(opts, deps) {
|
|
|
507
888
|
});
|
|
508
889
|
}
|
|
509
890
|
for (const { path } of plan.writes) {
|
|
510
|
-
const problem = await symlinkProblem(opts.dir, path);
|
|
891
|
+
const problem = await symlinkProblem(opts.dir, path, "adopt");
|
|
511
892
|
if (problem !== undefined)
|
|
512
893
|
plan.errors.push(problem);
|
|
513
894
|
}
|
|
514
895
|
return plan;
|
|
515
896
|
}
|
|
516
|
-
async function symlinkProblem(root, path) {
|
|
517
|
-
const parts = path.split("/");
|
|
518
|
-
for (let depth = 1; depth <= parts.length; depth++) {
|
|
519
|
-
const part = parts.slice(0, depth).join("/");
|
|
520
|
-
try {
|
|
521
|
-
const info = await lstat(join(root, part));
|
|
522
|
-
if (info.isSymbolicLink()) {
|
|
523
|
-
return `${part} is a symlink, and adopt does not write through a symlink`;
|
|
524
|
-
}
|
|
525
|
-
if (depth < parts.length && !info.isDirectory()) {
|
|
526
|
-
return `${part} is not a directory, and adopt writes ${path} below it`;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
catch (error) {
|
|
530
|
-
const { code } = error;
|
|
531
|
-
if (code === "ENOENT" || code === "ENOTDIR")
|
|
532
|
-
return undefined;
|
|
533
|
-
throw error;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
return undefined;
|
|
537
|
-
}
|
|
538
897
|
export async function applyAdopt(plan, opts) {
|
|
539
898
|
for (const { path, before } of plan.writes) {
|
|
540
|
-
const problem = await symlinkProblem(opts.dir, path);
|
|
899
|
+
const problem = await symlinkProblem(opts.dir, path, "adopt");
|
|
541
900
|
if (problem !== undefined)
|
|
542
901
|
throw new Error(problem);
|
|
543
|
-
if (before !== null
|
|
544
|
-
|
|
902
|
+
if (before !== null) {
|
|
903
|
+
const actual = await readFile(join(opts.dir, path)).catch(() => undefined);
|
|
904
|
+
if (!actual?.equals(Buffer.from(before, "utf8")))
|
|
905
|
+
throw new StaleAdoptPlanError(path);
|
|
545
906
|
}
|
|
546
907
|
}
|
|
547
|
-
const markers = new Set(["package.json", MANIFEST_FILE]);
|
|
908
|
+
const markers = new Set(["package.json", PYPROJECT, MANIFEST_FILE]);
|
|
548
909
|
const ordered = [
|
|
549
910
|
...plan.writes.filter(({ path }) => !markers.has(path)),
|
|
550
911
|
...plan.writes.filter(({ path }) => markers.has(path)),
|