@uipath/packager-tool-functions-browser 1.206.0-preview.301 → 1.207.0-preview.305

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 CHANGED
@@ -1,11 +1,15 @@
1
1
  # @uipath/packager-tool-functions-browser
2
2
 
3
- Browser packager tool for `ProjectType.Function`. It packs Functions projects through the UiPath Remote Agent, in the same Orchestrator job as the solution's RPA projects.
3
+ Browser packager tool for `ProjectType.Function`. It packs JS/TS Functions projects through the UiPath Remote Agent, in the same Orchestrator job as the solution's RPA projects, and Python Functions projects in the browser.
4
4
 
5
5
  ## Why
6
6
 
7
7
  The local `FunctionsTool` (`@uipath/packager-tool-functions`) runs in the browser, but it can only ship the `entry-points.json` and `bindings_v2.json` already in the snapshot. Generating them from the sources, as `uip function pack` does, needs Node, TypeScript and a real disk. When those files are stale, the pack still succeeds, but the deployed function has the wrong HTTP triggers. The Remote Agent can run the generator.
8
8
 
9
+ Python projects have nothing to generate: `uip solution pack` passes their manifests through as well. So the tool packs them in the browser with `@uipath/coded-functions-py-packager` and skips them in the agent job (`skipAsync`). A solution whose only remote projects are Python ones starts no job, and the robot needs no Node.js for them.
10
+
11
+ The language comes from `detectFunctionsLanguage` in `@uipath/functions-sdk/language` (bundled, like the Python packager), the same detection the local `FunctionsTool` uses: JS/TS goes to the agent, Python is packed here, and a project with no language signal fails as not initialized without reaching the agent.
12
+
9
13
  ## Usage
10
14
 
11
15
  Register it **instead of** `FunctionsToolFactory`. Both claim `Function`, and the first registration of a type wins:
@@ -20,9 +24,9 @@ toolsFactoryRepository.registerProjectToolFactory(new WorkflowCompilerToolFactor
20
24
 
21
25
  Both factories use the shared executor from `@uipath/packager-remote-agent-browser`, so Function and RPA projects pack in one agent job. Set `functionsPackagerVersion` on the pack options to pin the packager the agent restores.
22
26
 
23
- Only pack goes to the agent. A Functions project has nothing to validate or clean up, so validate and cleanup succeed locally and tell the shared executor to skip the project (`skipAsync`): the RPA projects' job does not wait for it and carries no `FunctionProjects`, and a Function-only solution starts no job. Restore and build are local no-ops.
27
+ Only pack goes to the agent, and only for JS/TS projects. A Functions project has nothing to validate or clean up, so validate and cleanup succeed locally and tell the shared executor to skip the project (`skipAsync`): the RPA projects' job does not wait for it and carries no `FunctionProjects`, and a Function-only solution starts no job. Restore and build are local no-ops.
24
28
 
25
29
  ## Requirements
26
30
 
27
- - A Remote Agent that packs `FunctionProjects`. An older one ignores the list and packs only the RPA projects; each Function project then fails with "The remote agent returned no package for …" when the result arrives.
31
+ - A Remote Agent that packs `FunctionProjects`. An older one ignores the list and packs only the RPA projects; each JS/TS Function project then fails with "The remote agent returned no package for …" when the result arrives.
28
32
  - The same pack options remote RPA packing needs: `connection` (`cloudUrl`, `accessToken`, `folderId`) and `downloadUrl`.
package/dist/index.js CHANGED
@@ -6,16 +6,336 @@ import {
6
6
  ProjectTypes
7
7
  } from "@uipath/solutionpackager-tool-core";
8
8
 
9
+ // ../coded-functions-py-packager/src/build-functions-package.ts
10
+ import { NugetConstants, Path } from "@uipath/solutionpackager-tool-core";
11
+
12
+ // ../coded-functions-py-packager/src/constants.ts
13
+ var EXCLUDED_NAMES = new Set([
14
+ "agent.json",
15
+ "project.uiproj",
16
+ "bindings.json",
17
+ "entry-points.json",
18
+ ".DS_Store",
19
+ "Thumbs.db"
20
+ ]);
21
+ var EXCLUDED_DIRECTORIES = new Set([
22
+ "evaluations",
23
+ ".function-builder",
24
+ "node_modules",
25
+ "__pycache__",
26
+ ".pytest_cache",
27
+ ".venv",
28
+ "venv",
29
+ "env",
30
+ ".git",
31
+ ".vscode",
32
+ ".idea",
33
+ ".local"
34
+ ]);
35
+ var CONTENT_TYPE = "function";
36
+ var TARGET_RUNTIME = "python";
37
+ var UIPATH_JSON_FILE_NAME = "uipath.json";
38
+ var BINDINGS_SOURCE_FILE_NAME = "bindings.json";
39
+ var BINDINGS_VERSION = "2.0";
40
+ var ENTRY_POINT_TYPE = "function";
41
+ var SCHEMA_BASE_URL = "https://cloud.uipath.com/draft/2024-12";
42
+ var SCHEMAS = {
43
+ Bindings: `${SCHEMA_BASE_URL}/bindings`,
44
+ EntryPoint: `${SCHEMA_BASE_URL}/entry-point`,
45
+ Operate: `${SCHEMA_BASE_URL}/operate`,
46
+ PackageDescriptor: `${SCHEMA_BASE_URL}/package-descriptor`
47
+ };
48
+
49
+ // ../coded-functions-py-packager/src/build-functions-package.ts
50
+ async function buildFunctionsPackage(fileSystem, options) {
51
+ const contentFolder = Path.join(options.outputPath, NugetConstants.ContentFolderName);
52
+ await validateProjectFiles(fileSystem, options.projectPath);
53
+ await copyFiles(fileSystem, options.projectPath, contentFolder);
54
+ await writeEntryPointsFile(fileSystem, options.projectPath, contentFolder);
55
+ await createOperateFile(fileSystem, contentFolder, options.projectStorageId);
56
+ await createBindingsFile(fileSystem, options.projectPath, contentFolder);
57
+ await createPackageDescriptor(fileSystem, options.outputPath);
58
+ }
59
+ async function validateProjectFiles(fileSystem, projectPath) {
60
+ const uipathJsonPath = Path.join(projectPath, UIPATH_JSON_FILE_NAME);
61
+ const entryPointsPath = Path.join(projectPath, NugetConstants.EntryPointsFileName);
62
+ if (!await fileSystem.exists(uipathJsonPath)) {
63
+ throw new Error("uipath.json is missing from the project.");
64
+ }
65
+ if (!await fileSystem.exists(entryPointsPath)) {
66
+ throw new Error("entry-points.json is missing from the project.");
67
+ }
68
+ }
69
+ async function copyFiles(fileSystem, sourcePath, destinationPath) {
70
+ await fileSystem.mkdir(destinationPath);
71
+ const entries = await fileSystem.readdir(sourcePath);
72
+ for (const entry of entries) {
73
+ const sourceFile = Path.join(sourcePath, entry);
74
+ const destinationFile = Path.join(destinationPath, entry);
75
+ const stat = await fileSystem.stat(sourceFile);
76
+ if (stat?.isFile()) {
77
+ if (EXCLUDED_NAMES.has(entry)) {
78
+ continue;
79
+ }
80
+ const content = await fileSystem.readFile(sourceFile);
81
+ if (content) {
82
+ await fileSystem.writeFile(destinationFile, content);
83
+ }
84
+ } else if (stat?.isDirectory()) {
85
+ if (EXCLUDED_DIRECTORIES.has(entry)) {
86
+ continue;
87
+ }
88
+ await copyFiles(fileSystem, sourceFile, destinationFile);
89
+ }
90
+ }
91
+ }
92
+ async function createOperateFile(fileSystem, contentFolder, projectStorageId) {
93
+ const operateJsonFilePath = Path.join(contentFolder, NugetConstants.OperateFileName);
94
+ const exists = await fileSystem.exists(operateJsonFilePath);
95
+ if (exists) {
96
+ return;
97
+ }
98
+ const entryPointsFilePath = Path.join(contentFolder, NugetConstants.EntryPointsFileName);
99
+ let mainPath = "";
100
+ const entryPointsExists = await fileSystem.exists(entryPointsFilePath);
101
+ if (entryPointsExists) {
102
+ const entryPointsContent = await fileSystem.readFile(entryPointsFilePath);
103
+ if (entryPointsContent) {
104
+ try {
105
+ const entryPointsText = new TextDecoder().decode(entryPointsContent);
106
+ const entryPoints = JSON.parse(entryPointsText);
107
+ mainPath = entryPoints.entryPoints?.[0]?.filePath ?? "";
108
+ } catch {}
109
+ }
110
+ }
111
+ const operateFileModel = {
112
+ $schema: SCHEMAS.Operate,
113
+ contentType: CONTENT_TYPE,
114
+ projectId: projectStorageId,
115
+ main: mainPath,
116
+ targetFramework: "Portable",
117
+ targetRuntime: TARGET_RUNTIME,
118
+ runtimeOptions: {
119
+ isAttended: false,
120
+ requiresUserInteraction: false,
121
+ isConversational: false
122
+ }
123
+ };
124
+ const operateJsonString = JSON.stringify(operateFileModel, null, 2);
125
+ await fileSystem.writeFile(operateJsonFilePath, operateJsonString);
126
+ }
127
+ async function writeEntryPointsFile(fileSystem, projectPath, contentFolder) {
128
+ const sourcePath = Path.join(projectPath, NugetConstants.EntryPointsFileName);
129
+ const destinationPath = Path.join(contentFolder, NugetConstants.EntryPointsFileName);
130
+ const raw = await fileSystem.readFile(sourcePath);
131
+ if (!raw) {
132
+ throw new Error("entry-points.json is missing from the project.");
133
+ }
134
+ let parsed;
135
+ try {
136
+ parsed = JSON.parse(new TextDecoder().decode(raw));
137
+ } catch {
138
+ throw new Error("entry-points.json is not valid JSON.");
139
+ }
140
+ const sourceEntries = Array.isArray(parsed.entryPoints) ? parsed.entryPoints : [];
141
+ const normalizedEntries = sourceEntries.map((entry) => ({
142
+ ...entry,
143
+ uniqueId: typeof entry.uniqueId === "string" && entry.uniqueId.length > 0 ? entry.uniqueId : crypto.randomUUID(),
144
+ type: typeof entry.type === "string" && entry.type.length > 0 ? entry.type : ENTRY_POINT_TYPE
145
+ }));
146
+ const normalized = {
147
+ $schema: SCHEMAS.EntryPoint,
148
+ $id: NugetConstants.EntryPointsFileName,
149
+ entryPoints: normalizedEntries
150
+ };
151
+ await fileSystem.writeFile(destinationPath, JSON.stringify(normalized, null, 2));
152
+ }
153
+ async function createBindingsFile(fileSystem, projectPath, contentFolder) {
154
+ const bindingsOutputPath = Path.join(contentFolder, NugetConstants.BindingsV2FileName);
155
+ const sourcePath = Path.join(projectPath, BINDINGS_SOURCE_FILE_NAME);
156
+ let bindings = null;
157
+ if (await fileSystem.exists(sourcePath)) {
158
+ const raw = await fileSystem.readFile(sourcePath);
159
+ if (raw) {
160
+ try {
161
+ bindings = JSON.parse(new TextDecoder().decode(raw));
162
+ } catch {
163
+ bindings = null;
164
+ }
165
+ }
166
+ }
167
+ if (bindings === null) {
168
+ bindings = {
169
+ $schema: SCHEMAS.Bindings,
170
+ version: BINDINGS_VERSION,
171
+ resources: []
172
+ };
173
+ }
174
+ await fileSystem.writeFile(bindingsOutputPath, JSON.stringify(bindings, null, 2));
175
+ }
176
+ async function createPackageDescriptor(fileSystem, localBuildFolder) {
177
+ const packageDescriptor = {
178
+ files: {}
179
+ };
180
+ addFileToDescriptor(packageDescriptor, NugetConstants.OperateFileName, NugetConstants.OperateFileName);
181
+ addFileToDescriptor(packageDescriptor, NugetConstants.EntryPointsFileName, NugetConstants.EntryPointsFileName);
182
+ addFileToDescriptor(packageDescriptor, NugetConstants.BindingsFileId, NugetConstants.BindingsV2FileName);
183
+ const packageDescriptorPath = Path.join(localBuildFolder, NugetConstants.ContentFolderName, NugetConstants.PackageDescriptorFileName);
184
+ const packageDescriptorJson = JSON.stringify({
185
+ $schema: SCHEMAS.PackageDescriptor,
186
+ ...packageDescriptor
187
+ }, null, 2);
188
+ await fileSystem.writeFile(packageDescriptorPath, packageDescriptorJson);
189
+ }
190
+ function addFileToDescriptor(packageDescriptor, key, fileName) {
191
+ const relativePath = Path.join(NugetConstants.ContentFolderName, fileName);
192
+ packageDescriptor.files[key] = relativePath;
193
+ }
194
+ // ../coded-functions-py-packager/src/pack-functions-package.ts
195
+ import {
196
+ NugetConstants as NugetConstants2,
197
+ NugetPackager,
198
+ Path as Path2,
199
+ TemporaryStorageService
200
+ } from "@uipath/solutionpackager-tool-core";
201
+ async function packFunctionsPackage(fileSystem, options) {
202
+ const temporaryStorage = new TemporaryStorageService(fileSystem);
203
+ try {
204
+ const buildFolder = Path2.join(await temporaryStorage.getTempFolderPath(), NugetConstants2.OutputFolderName);
205
+ await buildFunctionsPackage(fileSystem, {
206
+ projectPath: options.projectPath,
207
+ outputPath: buildFolder,
208
+ projectStorageId: options.projectStorageId
209
+ });
210
+ const nupkgPath = Path2.join(options.outputPath, `${options.package.id}.${options.package.version}.nupkg`);
211
+ const result = await new NugetPackager(fileSystem).packAsync(buildFolder, options.package, nupkgPath);
212
+ return result.outputPath;
213
+ } finally {
214
+ await temporaryStorage.cleanup();
215
+ }
216
+ }
217
+ // ../../functions-sdk/src/language.ts
218
+ var FunctionsLanguages = {
219
+ JavaScript: "javascript",
220
+ Python: "python"
221
+ };
222
+ var FunctionsLanguageLabels = {
223
+ [FunctionsLanguages.JavaScript]: "JS/TS",
224
+ [FunctionsLanguages.Python]: "Python"
225
+ };
226
+ var LANGUAGE_ALIASES = {
227
+ [FunctionsLanguages.JavaScript]: ["ts", "js", "javascript", "typescript"],
228
+ [FunctionsLanguages.Python]: ["py", "python"]
229
+ };
230
+ var NO_FUNCTIONS_LANGUAGE_SIGNAL = "no uipath.json functions map, no package.json and no pyproject.toml";
231
+ var EXTENSION_TO_LANGUAGE = {
232
+ ".ts": FunctionsLanguages.JavaScript,
233
+ ".js": FunctionsLanguages.JavaScript,
234
+ ".mjs": FunctionsLanguages.JavaScript,
235
+ ".py": FunctionsLanguages.Python
236
+ };
237
+ function functionsLanguageFromMap(functions) {
238
+ const firstEntry = Object.values(functions ?? {})[0];
239
+ if (!firstEntry) {
240
+ return;
241
+ }
242
+ const filePath = firstEntry.split(":")[0] ?? "";
243
+ const dot = filePath.lastIndexOf(".");
244
+ return dot >= 0 ? EXTENSION_TO_LANGUAGE[filePath.slice(dot)] : undefined;
245
+ }
246
+ async function detectFunctionsLanguage(fileSystem, projectPath) {
247
+ const fromManifest = await languageFromUipathJson(fileSystem, projectPath);
248
+ if (fromManifest) {
249
+ return fromManifest;
250
+ }
251
+ if (await fileSystem.exists(fileSystem.path.join(projectPath, "package.json"))) {
252
+ return FunctionsLanguages.JavaScript;
253
+ }
254
+ if (await fileSystem.exists(fileSystem.path.join(projectPath, "pyproject.toml"))) {
255
+ return FunctionsLanguages.Python;
256
+ }
257
+ return;
258
+ }
259
+ async function languageFromUipathJson(fileSystem, projectPath) {
260
+ const uipathJsonPath = fileSystem.path.join(projectPath, "uipath.json");
261
+ if (!await fileSystem.exists(uipathJsonPath)) {
262
+ return;
263
+ }
264
+ const content = await fileSystem.readFile(uipathJsonPath, "utf-8");
265
+ if (!content) {
266
+ return;
267
+ }
268
+ try {
269
+ const uipathJson = JSON.parse(content);
270
+ return functionsLanguageFromMap(uipathJson.functions);
271
+ } catch {
272
+ return;
273
+ }
274
+ }
275
+
9
276
  // src/remote-functions-tool.ts
10
- import { RemoteAgentProjectTool } from "@uipath/packager-remote-agent-browser";
11
277
  import {
12
- ensureProjectId
278
+ BundleOperation,
279
+ RemoteAgentProjectTool
280
+ } from "@uipath/packager-remote-agent-browser";
281
+ import {
282
+ ensureProjectId,
283
+ ToolErrorCodes,
284
+ ToolResult
13
285
  } from "@uipath/solutionpackager-tool-core";
14
286
 
15
287
  class RemoteFunctionsTool extends RemoteAgentProjectTool {
288
+ async packAsync(options, cancellationToken) {
289
+ const context = this.context;
290
+ if (!context) {
291
+ return super.packAsync(options, cancellationToken);
292
+ }
293
+ let language;
294
+ try {
295
+ language = await detectFunctionsLanguage(this.fileSystem, options.projectPath);
296
+ } catch (error) {
297
+ return this.skipWithErrorAsync(options, context, `Pack failed for Function project at ${options.projectPath}: ${errorMessage(error)}`);
298
+ }
299
+ if (language === FunctionsLanguages.JavaScript) {
300
+ return super.packAsync(options, cancellationToken);
301
+ }
302
+ if (language === undefined) {
303
+ return this.skipWithErrorAsync(options, context, `Function project at ${options.projectPath} is not initialized: it has ${NO_FUNCTIONS_LANGUAGE_SIGNAL}.`, "Initialize the project, then pack again.");
304
+ }
305
+ return this.packPythonAsync(options, context);
306
+ }
16
307
  async resolveProjectIdAsync(options) {
17
308
  return options.projectStorageId || await ensureProjectId(options.projectPath, this.fileSystem);
18
309
  }
310
+ async packPythonAsync(options, context) {
311
+ await this.skipPackAsync(options, context);
312
+ try {
313
+ this.logger.progress("Packing Python Functions project...");
314
+ const nupkgPath = await packFunctionsPackage(this.fileSystem, {
315
+ projectPath: options.projectPath,
316
+ projectStorageId: await this.resolveProjectIdAsync(options),
317
+ package: options.package,
318
+ outputPath: options.outputPath
319
+ });
320
+ this.logger.progress("Package created successfully.");
321
+ return new ToolResult(ToolErrorCodes.Success, "Pack completed successfully.", [nupkgPath]);
322
+ } catch (error) {
323
+ const message = `Pack failed for Function project at ${options.projectPath} (Python): ${errorMessage(error)}`;
324
+ this.logger.error(message);
325
+ return ToolResult.error(ToolErrorCodes.InternalError, message);
326
+ }
327
+ }
328
+ async skipWithErrorAsync(options, context, message, instructions) {
329
+ await this.skipPackAsync(options, context);
330
+ this.logger.error(message);
331
+ return ToolResult.error(ToolErrorCodes.InternalError, message, instructions);
332
+ }
333
+ async skipPackAsync(options, context) {
334
+ await this.bundleExecutor.skipAsync(BundleOperation.Pack, options.projectPath, context);
335
+ }
336
+ }
337
+ function errorMessage(error) {
338
+ return error instanceof Error ? error.message : String(error);
19
339
  }
20
340
 
21
341
  // src/remote-functions-tool-factory.ts
@@ -29,4 +349,4 @@ export {
29
349
  RemoteFunctionsToolFactory
30
350
  };
31
351
 
32
- //# debugId=57F0E44E9DE9F84A64756E2164756E21
352
+ //# debugId=8C3F0EF11BB5B49864756E2164756E21
@@ -1,20 +1,31 @@
1
1
  import { RemoteAgentProjectTool } from "@uipath/packager-remote-agent-browser";
2
- import { type IProjectPackOptions } from "@uipath/solutionpackager-tool-core";
2
+ import { type IProjectPackOptions, ToolResult } from "@uipath/solutionpackager-tool-core";
3
3
  /**
4
- * Browser Functions tool that packs through the Remote Agent.
4
+ * Browser Functions tool that packs JS/TS projects through the Remote Agent
5
+ * and Python projects in the browser.
5
6
  *
6
- * The browser cannot generate a Functions project's `entry-points.json` and
7
+ * The browser cannot generate a JS/TS project's `entry-points.json` and
7
8
  * `bindings_v2.json` from its sources (that needs Node, TypeScript and a real
8
- * disk), so the local `FunctionsTool` ships whatever manifests are in the
9
- * snapshot. This tool hands the project to the shared remote-agent bundle
10
- * executor instead: it is packed by the agent in the same Orchestrator job as
11
- * the solution's RPA projects, and the package comes back through the same
9
+ * disk), so this tool hands those projects to the shared remote-agent bundle
10
+ * executor: they are packed by the agent in the same Orchestrator job as the
11
+ * solution's RPA projects, and the package comes back through the same
12
12
  * bucket.
13
13
  *
14
+ * A Python project has nothing for the agent to generate: its manifests come
15
+ * from the project as designed, as they do in `uip solution pack`. It is
16
+ * packed here and skipped in the bundle, so the job does not wait for it and
17
+ * a solution with no other remote project starts no job, and the robot needs
18
+ * no Node.js for it.
19
+ *
14
20
  * Only pack goes to the agent. A Functions project has nothing to validate or
15
21
  * clean up (the local `FunctionsTool` does neither), so validate and cleanup
16
22
  * succeed here and tell the bundle to skip the project.
17
23
  */
18
24
  export declare class RemoteFunctionsTool extends RemoteAgentProjectTool {
25
+ packAsync(options: IProjectPackOptions, cancellationToken?: AbortSignal): Promise<ToolResult>;
19
26
  protected resolveProjectIdAsync(options: IProjectPackOptions): Promise<string>;
27
+ private packPythonAsync;
28
+ /** Fails a project the agent will not get, without making its job wait. */
29
+ private skipWithErrorAsync;
30
+ private skipPackAsync;
20
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/packager-tool-functions-browser",
3
- "version": "1.206.0-preview.301",
3
+ "version": "1.207.0-preview.305",
4
4
  "description": "UiPath Functions tool - browser implementation that packs through the Remote Agent",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,8 +21,8 @@
21
21
  "author": "UiPath",
22
22
  "license": "SEE LICENSE IN LICENSE.txt",
23
23
  "peerDependencies": {
24
- "@uipath/packager-remote-agent-browser": "1.206.0",
25
- "@uipath/solutionpackager-tool-core": "1.206.0"
24
+ "@uipath/packager-remote-agent-browser": "1.207.0",
25
+ "@uipath/solutionpackager-tool-core": "1.207.0"
26
26
  },
27
- "gitHead": "078afc3ef7ebf4c38353ee0059e321acf16a350d"
27
+ "gitHead": "1600aa89255c37c1b8bc68d9882c3395c1d5bff4"
28
28
  }