@trackunit/iris-app 1.3.48 → 1.3.50

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/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 1.3.50 (2025-03-31)
2
+
3
+ ### 🧱 Updated Dependencies
4
+
5
+ - Updated iris-app-build-utilities to 1.3.50
6
+ - Updated iris-app-webpack-plugin to 1.3.50
7
+ - Updated iris-app-api to 1.3.50
8
+ - Updated shared-utils to 1.5.48
9
+
10
+ ## 1.3.49 (2025-03-31)
11
+
12
+ ### 🧱 Updated Dependencies
13
+
14
+ - Updated iris-app-build-utilities to 1.3.49
15
+ - Updated iris-app-webpack-plugin to 1.3.49
16
+ - Updated iris-app-api to 1.3.49
17
+ - Updated shared-utils to 1.5.47
18
+
1
19
  ## 1.3.48 (2025-03-27)
2
20
 
3
21
  ### 🧱 Updated Dependencies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/iris-app",
3
- "version": "1.3.48",
3
+ "version": "1.3.50",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "main": "src/index.js",
6
6
  "generators": "./generators.json",
@@ -33,10 +33,10 @@
33
33
  "@npmcli/arborist": "^7.3.1",
34
34
  "webpack-bundle-analyzer": "^4.8.0",
35
35
  "win-ca": "^3.5.1",
36
- "@trackunit/iris-app-build-utilities": "1.3.48",
37
- "@trackunit/shared-utils": "1.5.46",
38
- "@trackunit/iris-app-api": "1.3.48",
39
- "@trackunit/iris-app-webpack-plugin": "1.3.48",
36
+ "@trackunit/iris-app-build-utilities": "1.3.50",
37
+ "@trackunit/shared-utils": "1.5.48",
38
+ "@trackunit/iris-app-api": "1.3.50",
39
+ "@trackunit/iris-app-webpack-plugin": "1.3.50",
40
40
  "tslib": "^2.6.2"
41
41
  },
42
42
  "types": "./src/index.d.ts",
@@ -0,0 +1 @@
1
+ OPENAI_API_KEY=Your-OpenAI-API-Key
@@ -0,0 +1,13 @@
1
+ import { AiAgentExtensionManifest } from '@trackunit/iris-app-api';
2
+
3
+ const aiAgentExtensionManifest: AiAgentExtensionManifest = {
4
+ id: "<%= projectName %>",
5
+ type: "AI_AGENT_EXTENSION",
6
+ runtime: "DENO",
7
+ sourceRoot: "<%= sourceRoot %>/index.ts",
8
+ dependencyDefinitionFile: "<%= dependencyDefinitionFile %>",
9
+ name: "Deno Worker <%= projectName %>",
10
+ main: "index.ts",
11
+ };
12
+
13
+ export default aiAgentExtensionManifest;
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "<%= importPath %>",
3
+ "dependencies": {
4
+ "@ai-sdk/openai": "1.3.3",
5
+ "ai": "4.2.7",
6
+ "cors": "^2.8.5",
7
+ "express": "4.21.2"
8
+ }
9
+ }
@@ -0,0 +1,81 @@
1
+ import { createOpenAI } from "@ai-sdk/openai";
2
+ import { coreMessageSchema, generateText, streamText } from "ai";
3
+ import cors from "cors";
4
+ import express, { Request, Response } from "express";
5
+
6
+ // Log the current working directory
7
+ console.log("Current working directory:", Deno.cwd());
8
+
9
+ const app = express();
10
+ app.use(cors());
11
+ app.use(express.json());
12
+
13
+ const openai = createOpenAI({
14
+ apiKey: Deno.env.get("OPENAI_API_KEY"),
15
+ });
16
+
17
+ const defaultAgentConfig = {
18
+ model: openai("gpt-4o"),
19
+ system: `You are Agent, a specialized AI Agent for construction professionals using the Trackunit Manager app.
20
+
21
+ You should:
22
+ - Provide concise, professional responses focused on construction equipment and fleet management
23
+ - Understand common construction industry terminology and workflows
24
+ - Help users analyze equipment data, troubleshoot issues, and optimize fleet operations
25
+ - Offer actionable insights that improve productivity and reduce downtime
26
+ - Respect data privacy and security at all times
27
+
28
+ When discussing equipment:
29
+ - Focus on maintenance schedules, utilization rates, and performance metrics
30
+ - Help interpret fault codes and suggest potential solutions
31
+ - Provide context about industry standards and best practices
32
+
33
+ Users might refer to construction equipment as assets, in that case it could be machines, vehicles, or other equipment like tools.
34
+
35
+ If you're uncertain about something, acknowledge your limitations and suggest where the user might find more information.
36
+
37
+ Always prioritize safety and compliance in your recommendations.`,
38
+ };
39
+
40
+ const handleRequest = async (req: Request, res: Response, useStream: boolean) => {
41
+ try {
42
+ // Validate the request body against the coreMessageSchema
43
+ const parseResult = coreMessageSchema.array().safeParse(req.body.messages);
44
+
45
+ if (!parseResult.success) {
46
+ return res.status(400).json({
47
+ error: "Invalid message format",
48
+ details: parseResult.error.format(),
49
+ });
50
+ }
51
+
52
+ const messages = parseResult.data;
53
+
54
+ if (useStream) {
55
+ const streamResult = streamText({
56
+ ...defaultAgentConfig,
57
+ messages,
58
+ });
59
+
60
+ return streamResult.pipeDataStreamToResponse(res, {
61
+ sendReasoning: true,
62
+ });
63
+ }
64
+
65
+ const generateResult = await generateText({
66
+ ...defaultAgentConfig,
67
+ messages,
68
+ });
69
+ return res.json(generateResult);
70
+ } catch (error) {
71
+ if (!res.headersSent) {
72
+ res.status(500).json({ error: "Internal server error" });
73
+ }
74
+ }
75
+ };
76
+
77
+ app.post("/agent/stream", (req: Request, res: Response) => handleRequest(req, res, true));
78
+ app.post("/agent/generate", (req: Request, res: Response) => handleRequest(req, res, false));
79
+
80
+ const port = process.env.PORT || 8000;
81
+ app.listen(port);
@@ -3,7 +3,8 @@ import { ServerlessFunctionExtensionManifest } from '@trackunit/iris-app-api';
3
3
  const serverlessFunctionExtensionManifest: ServerlessFunctionExtensionManifest = {
4
4
  id: "<%= projectName %>",
5
5
  type: "SERVERLESS_FUNCTION_EXTENSION",
6
- sourceRoot: "<%= sourceRoot %>",
6
+ runtime: "DENO",
7
+ sourceRoot: "<%= sourceRoot %>/index.ts",
7
8
  dependencyDefinitionFile: "<%= dependencyDefinitionFile %>",
8
9
  name: "Deno Worker <%= projectName %>",
9
10
  main: "index.ts",
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "<%= importPath %>"",
2
+ "name": "<%= importPath %>",
3
3
  "dependencies": {
4
4
  }
5
5
  }
@@ -65,7 +65,6 @@ const IrisAppExtensionGenerator = async function (tree, options) {
65
65
  if (!tree.exists(manifestPath)) {
66
66
  throw new Error(`The app does not have an iris-app-manifest.ts: ${manifestPath} make sure you enter the right app name, which has an iris-app-manifest.ts`);
67
67
  }
68
- (0, devkit_1.generateFiles)(tree, path.join(__dirname, "files", irisAppExtensionType), normalizedOptions.projectRoot, templateOptions);
69
68
  if (normalizedOptions.updatePackageJson) {
70
69
  (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
71
70
  ...dependencies_1.spaDependencies,
@@ -85,6 +84,7 @@ const IrisAppExtensionGenerator = async function (tree, options) {
85
84
  skipPackageJson: true,
86
85
  };
87
86
  await (0, react_1.libraryGenerator)(tree, schema);
87
+ (0, devkit_1.generateFiles)(tree, path.join(__dirname, "files", irisAppExtensionType), normalizedOptions.projectRoot, templateOptions);
88
88
  if (!iris_app_api_1.nonUiExtensionTypes.includes(irisAppExtensionType)) {
89
89
  (0, devkit_1.generateFiles)(tree, path.join(__dirname, "files", "react-app"), normalizedOptions.projectRoot, templateOptions);
90
90
  }
@@ -108,6 +108,18 @@ const IrisAppExtensionGenerator = async function (tree, options) {
108
108
  ];
109
109
  return tsConfigBase;
110
110
  });
111
+ // Add working serve target to the project.json for DENO extensions
112
+ if (iris_app_api_1.serverSideExtensionTypes.includes(irisAppExtensionType)) {
113
+ (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(normalizedOptions.projectRoot, "project.json"), projectJson => {
114
+ projectJson.targets.serve = {
115
+ executor: "nx:run-commands",
116
+ options: {
117
+ command: `deno run --env-file=libs/${normalizedOptions.projectDirectory}/.env --allow-env --allow-net --allow-read ${normalizedOptions.sourceRoot}/index.ts`,
118
+ },
119
+ };
120
+ return projectJson;
121
+ });
122
+ }
111
123
  //TODO: Change the following to update the manifest in the virtual Tree - not on the file system.
112
124
  const project = new ts_morph_1.Project({
113
125
  tsConfigFilePath: `${(0, devkit_1.getWorkspaceLayout)(tree).appsDir}/${normalizedOptions.app}/tsconfig.app.json`,
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/iris-app-sdk/iris-app/src/generators/extend/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAWoB;AACpB,uCAAoC;AACpC,+BAAmD;AACnD,+EAA0E;AAC1E,qCAA6C;AAE7C,0DAAwF;AACxF,uCAAkC;AAClC,+CAAyB;AACzB,mDAA6B;AAC7B,yCAAsC;AACtC,uCAAoE;AACpE,uDAA+D;AAC/D,yDAA2D;AAC3D,iDAAmE;AAanE,SAAS,gBAAgB,CAAC,IAAU,EAAE,OAAwC;IAC5E,MAAM,IAAI,GAAG,IAAA,cAAK,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC;IAC1C,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAA,cAAK,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACnG,MAAM,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IACxE,MAAM,gBAAgB,GAAG,IAAA,qBAAS,EAAC,WAAW,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,GAAG,QAAQ,CAAC,OAAO,IAAI,gBAAgB,EAAE,CAAC;IAC9D,MAAM,UAAU,GAAG,GAAG,QAAQ,CAAC,OAAO,IAAI,gBAAgB,MAAM,CAAC;IACjE,MAAM,wBAAwB,GAAG,GAAG,QAAQ,CAAC,OAAO,IAAI,gBAAgB,eAAe,CAAC;IAExF,MAAM,QAAQ,GAAG,IAAA,2BAAW,EAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK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C,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;aACpC,CAAC;YACF,MAAM,IAAA,iBAAM,EAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,MAAc,EAAE,EAAE;gBACjD,8CAA8C;gBAC9C,2DAA2D;gBAC3D,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,kBAAe,iCAAyB,CAAC","sourcesContent":["import {\n addDependenciesToPackageJson,\n formatFiles,\n generateFiles,\n getWorkspaceLayout,\n installPackagesTask,\n joinPathFragments,\n names,\n offsetFromRoot,\n Tree,\n updateJson,\n} from \"@nx/devkit\";\nimport { Linter } from \"@nx/eslint\";\nimport { getRootTsConfigPathInTree } from \"@nx/js\";\nimport { getNpmScope } from \"@nx/js/src/utils/package-json/get-npm-scope\";\nimport { libraryGenerator } from \"@nx/react\";\nimport { Schema } from \"@nx/react/src/generators/library/schema\";\nimport { nonUiExtensionTypes, serverSideExtensionTypes } from \"@trackunit/iris-app-api\";\nimport { prompt } from \"enquirer\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { camelCase } from \"string-ts\";\nimport { Project, SyntaxKind, VariableDeclaration } from \"ts-morph\";\nimport { addPropertyWithName } from \"../../utils/ast/astUtils\";\nimport { updateFileInTree } from \"../../utils/fileUpdater\";\nimport { spaDependencies, testDependencies } from \"./dependencies\";\nimport { IrisAppExtensionGeneratorSchema } from \"./schema\";\n\ninterface NormalizedSchema extends IrisAppExtensionGeneratorSchema {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n projectCamelcase: string;\n importPath: string;\n sourceRoot: string;\n dependencyDefinitionFile: string;\n}\n\nfunction normalizeOptions(tree: Tree, options: IrisAppExtensionGeneratorSchema): NormalizedSchema {\n const name = names(options.name).fileName;\n const projectDirectory = options.directory ? `${names(options.directory).fileName}/${name}` : name;\n const projectName = projectDirectory.replace(new RegExp(\"/\", \"g\"), \"-\");\n const projectCamelcase = camelCase(projectName);\n const wsLayout = getWorkspaceLayout(tree);\n const projectRoot = `${wsLayout.libsDir}/${projectDirectory}`;\n const sourceRoot = `${wsLayout.libsDir}/${projectDirectory}/src`;\n const dependencyDefinitionFile = `${wsLayout.libsDir}/${projectDirectory}/package.json`;\n\n const npmScope = getNpmScope(tree);\n if (!npmScope) {\n throw new Error(\"Could not find npm scope in package.json\");\n }\n const importPath = `@${npmScope}/${projectName}`;\n\n return {\n ...options,\n projectName,\n projectRoot,\n projectDirectory,\n projectCamelcase,\n importPath,\n sourceRoot,\n dependencyDefinitionFile,\n };\n}\n\n/**\n * Iris App Extension Generator.\n *\n * @param tree the nx tree\n * @param options the generator options\n * @returns { Promise<void> } void\n */\nexport const IrisAppExtensionGenerator = async function (tree: Tree, options: IrisAppExtensionGeneratorSchema) {\n const adjustedOptions = await updateAppName(tree, options);\n\n const normalizedOptions = normalizeOptions(tree, adjustedOptions);\n\n const templateOptions = {\n ...normalizedOptions,\n ...names(normalizedOptions.name),\n offsetFromRoot: offsetFromRoot(normalizedOptions.projectRoot),\n template: \"\",\n };\n const irisAppExtensionType = normalizedOptions.type;\n\n if (!tree.exists(`${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}`)) {\n throw new Error(\n `The app does not exist: ${getWorkspaceLayout(tree).appsDir}/${\n normalizedOptions.app\n } make sure you enter the right app name`\n );\n }\n\n const manifestPath = `${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}/iris-app-manifest.ts`;\n if (!tree.exists(manifestPath)) {\n throw new Error(\n `The app does not have an iris-app-manifest.ts: ${manifestPath} make sure you enter the right app name, which has an iris-app-manifest.ts`\n );\n }\n generateFiles(\n tree,\n path.join(__dirname, \"files\", irisAppExtensionType),\n normalizedOptions.projectRoot,\n templateOptions\n );\n\n if (normalizedOptions.updatePackageJson) {\n addDependenciesToPackageJson(\n tree,\n {},\n {\n ...spaDependencies,\n ...testDependencies,\n }\n );\n }\n\n const schema: Schema = {\n name: normalizedOptions.projectName,\n style: \"none\",\n skipFormat: false,\n strict: true,\n unitTestRunner: \"jest\",\n linter: Linter.EsLint,\n routing: false,\n directory: normalizedOptions.projectRoot,\n skipTsConfig: false,\n skipPackageJson: true,\n };\n await libraryGenerator(tree, schema);\n\n if (!nonUiExtensionTypes.includes(irisAppExtensionType)) {\n generateFiles(tree, path.join(__dirname, \"files\", \"react-app\"), normalizedOptions.projectRoot, templateOptions);\n }\n\n const rootTsConfigPath = getRootTsConfigPathInTree(tree);\n if (!rootTsConfigPath) {\n throw new Error(\"Could not find root tsconfig.json\");\n }\n updateJson(tree, rootTsConfigPath, tsConfigBase => {\n // For server side extension types, we need to add deno types to the tsconfig and make Typescript accept Deno import syntax\n if (serverSideExtensionTypes.includes(irisAppExtensionType)) {\n tsConfigBase.compilerOptions = {\n ...tsConfigBase.compilerOptions,\n types: [\"deno\"],\n allowImportingTsExtensions: true,\n emitDeclarationOnly: true,\n declaration: true,\n };\n }\n\n tsConfigBase.compilerOptions.paths[normalizedOptions.importPath] = [\n path.join(normalizedOptions.projectRoot, \"extension-manifest.ts\"),\n ];\n return tsConfigBase;\n });\n\n //TODO: Change the following to update the manifest in the virtual Tree - not on the file system.\n const project = new Project({\n tsConfigFilePath: `${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}/tsconfig.app.json`,\n });\n\n const manifest = project.getSourceFileOrThrow(manifestPath);\n\n manifest.addImportDeclaration({\n moduleSpecifier: normalizedOptions.importPath,\n defaultImport: normalizedOptions.projectCamelcase,\n });\n\n // Get the default export symbol from the manifest\n const defaultExportSymbol = manifest.getDefaultExportSymbolOrThrow();\n\n // Get the aliased symbol if the default export is an alias\n const aliasedSymbol = defaultExportSymbol.getAliasedSymbol() || defaultExportSymbol;\n\n // Get the declaration of the aliased symbol\n const declaration = aliasedSymbol.getDeclarations()[0];\n\n if (!VariableDeclaration.isVariableDeclaration(declaration)) {\n throw new Error(\"Expected variable declaration\");\n }\n const irisAppManifestObject = declaration.getInitializer()?.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n if (!irisAppManifestObject) {\n throw new Error(`irisAppManifest not exported from the file: ${manifestPath}`);\n }\n // Find the extensions property within the irisAppManifest object\n const extensionsProperty = irisAppManifestObject.getPropertyOrThrow(\"extensions\");\n\n if (extensionsProperty.getKind() === SyntaxKind.PropertyAssignment) {\n const extensionsArray = extensionsProperty.getFirstChildByKindOrThrow(SyntaxKind.ArrayLiteralExpression);\n extensionsArray.addElement(`${normalizedOptions.projectCamelcase}`);\n }\n\n await manifest.save();\n\n if (!serverSideExtensionTypes.includes(irisAppExtensionType)) {\n tree.delete(joinPathFragments(normalizedOptions.projectRoot, \"src\", \"index.ts\"));\n }\n\n updateJson(tree, joinPathFragments(normalizedOptions.projectRoot, \"tsconfig.spec.json\"), tsConfigSpec => {\n // extension-manifest.ts is a build time file, so we only need to include it in the spec file for type/lint checking\n tsConfigSpec.include = [...tsConfigSpec.include, \"extension-manifest.ts\"];\n return tsConfigSpec;\n });\n\n updateFileInTree(tree, joinPathFragments(normalizedOptions.projectRoot, \"jest.config.ts\"), fileContent =>\n addPropertyWithName(fileContent, \"moduleNameMapper\", {\n \"@trackunit/css-core\": \"jest-transform-stub\",\n \"@trackunit/ui-icons/icons-sprite-mini.svg\": \"jest-transform-stub\",\n \"@trackunit/ui-icons/icons-sprite-outline.svg\": \"jest-transform-stub\",\n \"@trackunit/ui-icons/icons-sprite-solid.svg\": \"jest-transform-stub\",\n \"@trackunit/ui-icons/icons-sprite-micro.svg\": \"jest-transform-stub\",\n })\n );\n\n await formatFiles(tree);\n installPackagesTask(tree, true);\n return () => {\n // eslint-disable-next-line no-console\n console.log(\"🥳 Successfully created an app extensions and it is already added to the Iris App!\");\n };\n};\nconst updateAppName = async (tree: Tree, options: IrisAppExtensionGeneratorSchema) => {\n if (!options.app) {\n const folders = fs\n .readdirSync(getWorkspaceLayout(tree).appsDir, { withFileTypes: true })\n .filter(item => item.isDirectory());\n\n const tileApps: string[] = [];\n\n folders.forEach(folder => {\n const irisAppManifest = fs\n .readdirSync(`${getWorkspaceLayout(tree).appsDir}/${folder.name}`, { withFileTypes: true })\n .find(item => item.name === \"iris-app-manifest.ts\");\n\n if (irisAppManifest) {\n tileApps.push(folder.name);\n } else {\n const subFolders = fs\n .readdirSync(path.join(getWorkspaceLayout(tree).appsDir, folder.name), { withFileTypes: true })\n .filter(item => item.isDirectory());\n subFolders.forEach(subFolder => {\n const subDirIrisAppManifest = fs\n .readdirSync(`${getWorkspaceLayout(tree).appsDir}/${folder.name}/${subFolder.name}`, {\n withFileTypes: true,\n })\n .find(item => item.name === \"iris-app-manifest.ts\");\n\n if (subDirIrisAppManifest) {\n tileApps.push(path.join(folder.name, subFolder.name));\n }\n });\n }\n });\n\n if (tileApps.length === 1) {\n options.app = tileApps[0] || \"<Missing iris app name>\";\n } else if (tileApps.length === 0) {\n throw new Error(\"Please add an iris-app using: nx g @trackunit/iris-app:create \");\n } else {\n const promptObject = {\n name: \"app\",\n message: \"Select the iris app that this extension should belong to:\",\n type: \"autocomplete\",\n choices: tileApps.map(item => item),\n };\n await prompt(promptObject).then((values: object) => {\n // @ts-ignore - suppressImplicitAnyIndexErrors\n // eslint-disable-next-line @typescript-eslint/dot-notation\n options.app = values[\"app\"];\n });\n }\n }\n return options;\n};\n\nexport default IrisAppExtensionGenerator;\n"]}
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../libs/iris-app-sdk/iris-app/src/generators/extend/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAWoB;AACpB,uCAAoC;AACpC,+BAAmD;AACnD,+EAA0E;AAC1E,qCAA6C;AAE7C,0DAAwF;AACxF,uCAAkC;AAClC,+CAAyB;AACzB,mDAA6B;AAC7B,yCAAsC;AACtC,uCAAoE;AACpE,uDAA+D;AAC/D,yDAA2D;AAC3D,iDAAmE;AAanE,SAAS,gBAAgB,CAAC,IA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AAI,EAAE,KAAK;gBACX,OAAO,EAAE,2DAA2D;gBACpE,IAAI,EAAE,cAAc;gBACpB,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;aACpC,CAAC;YACF,MAAM,IAAA,iBAAM,EAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,MAAc,EAAE,EAAE;gBACjD,8CAA8C;gBAC9C,2DAA2D;gBAC3D,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,kBAAe,iCAAyB,CAAC","sourcesContent":["import {\n addDependenciesToPackageJson,\n formatFiles,\n generateFiles,\n getWorkspaceLayout,\n installPackagesTask,\n joinPathFragments,\n names,\n offsetFromRoot,\n Tree,\n updateJson,\n} from \"@nx/devkit\";\nimport { Linter } from \"@nx/eslint\";\nimport { getRootTsConfigPathInTree } from \"@nx/js\";\nimport { getNpmScope } from \"@nx/js/src/utils/package-json/get-npm-scope\";\nimport { libraryGenerator } from \"@nx/react\";\nimport { Schema } from \"@nx/react/src/generators/library/schema\";\nimport { nonUiExtensionTypes, serverSideExtensionTypes } from \"@trackunit/iris-app-api\";\nimport { prompt } from \"enquirer\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { camelCase } from \"string-ts\";\nimport { Project, SyntaxKind, VariableDeclaration } from \"ts-morph\";\nimport { addPropertyWithName } from \"../../utils/ast/astUtils\";\nimport { updateFileInTree } from \"../../utils/fileUpdater\";\nimport { spaDependencies, testDependencies } from \"./dependencies\";\nimport { IrisAppExtensionGeneratorSchema } from \"./schema\";\n\ninterface NormalizedSchema extends IrisAppExtensionGeneratorSchema {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n projectCamelcase: string;\n importPath: string;\n sourceRoot: string;\n dependencyDefinitionFile: string;\n}\n\nfunction normalizeOptions(tree: Tree, options: IrisAppExtensionGeneratorSchema): NormalizedSchema {\n const name = names(options.name).fileName;\n const projectDirectory = options.directory ? `${names(options.directory).fileName}/${name}` : name;\n const projectName = projectDirectory.replace(new RegExp(\"/\", \"g\"), \"-\");\n const projectCamelcase = camelCase(projectName);\n const wsLayout = getWorkspaceLayout(tree);\n const projectRoot = `${wsLayout.libsDir}/${projectDirectory}`;\n const sourceRoot = `${wsLayout.libsDir}/${projectDirectory}/src`;\n const dependencyDefinitionFile = `${wsLayout.libsDir}/${projectDirectory}/package.json`;\n\n const npmScope = getNpmScope(tree);\n if (!npmScope) {\n throw new Error(\"Could not find npm scope in package.json\");\n }\n const importPath = `@${npmScope}/${projectName}`;\n\n return {\n ...options,\n projectName,\n projectRoot,\n projectDirectory,\n projectCamelcase,\n importPath,\n sourceRoot,\n dependencyDefinitionFile,\n };\n}\n\n/**\n * Iris App Extension Generator.\n *\n * @param tree the nx tree\n * @param options the generator options\n * @returns { Promise<void> } void\n */\nexport const IrisAppExtensionGenerator = async function (tree: Tree, options: IrisAppExtensionGeneratorSchema) {\n const adjustedOptions = await updateAppName(tree, options);\n\n const normalizedOptions = normalizeOptions(tree, adjustedOptions);\n\n const templateOptions = {\n ...normalizedOptions,\n ...names(normalizedOptions.name),\n offsetFromRoot: offsetFromRoot(normalizedOptions.projectRoot),\n template: \"\",\n };\n const irisAppExtensionType = normalizedOptions.type;\n\n if (!tree.exists(`${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}`)) {\n throw new Error(\n `The app does not exist: ${getWorkspaceLayout(tree).appsDir}/${\n normalizedOptions.app\n } make sure you enter the right app name`\n );\n }\n\n const manifestPath = `${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}/iris-app-manifest.ts`;\n if (!tree.exists(manifestPath)) {\n throw new Error(\n `The app does not have an iris-app-manifest.ts: ${manifestPath} make sure you enter the right app name, which has an iris-app-manifest.ts`\n );\n }\n\n if (normalizedOptions.updatePackageJson) {\n addDependenciesToPackageJson(\n tree,\n {},\n {\n ...spaDependencies,\n ...testDependencies,\n }\n );\n }\n\n const schema: Schema = {\n name: normalizedOptions.projectName,\n style: \"none\",\n skipFormat: false,\n strict: true,\n unitTestRunner: \"jest\",\n linter: Linter.EsLint,\n routing: false,\n directory: normalizedOptions.projectRoot,\n skipTsConfig: false,\n skipPackageJson: true,\n };\n\n await libraryGenerator(tree, schema);\n\n generateFiles(\n tree,\n path.join(__dirname, \"files\", irisAppExtensionType),\n normalizedOptions.projectRoot,\n templateOptions\n );\n\n if (!nonUiExtensionTypes.includes(irisAppExtensionType)) {\n generateFiles(tree, path.join(__dirname, \"files\", \"react-app\"), normalizedOptions.projectRoot, templateOptions);\n }\n\n const rootTsConfigPath = getRootTsConfigPathInTree(tree);\n if (!rootTsConfigPath) {\n throw new Error(\"Could not find root tsconfig.json\");\n }\n updateJson(tree, rootTsConfigPath, tsConfigBase => {\n // For server side extension types, we need to add deno types to the tsconfig and make Typescript accept Deno import syntax\n if (serverSideExtensionTypes.includes(irisAppExtensionType)) {\n tsConfigBase.compilerOptions = {\n ...tsConfigBase.compilerOptions,\n types: [\"deno\"],\n allowImportingTsExtensions: true,\n emitDeclarationOnly: true,\n declaration: true,\n };\n }\n\n tsConfigBase.compilerOptions.paths[normalizedOptions.importPath] = [\n path.join(normalizedOptions.projectRoot, \"extension-manifest.ts\"),\n ];\n return tsConfigBase;\n });\n\n // Add working serve target to the project.json for DENO extensions\n if (serverSideExtensionTypes.includes(irisAppExtensionType)) {\n updateJson(tree, joinPathFragments(normalizedOptions.projectRoot, \"project.json\"), projectJson => {\n projectJson.targets.serve = {\n executor: \"nx:run-commands\",\n options: {\n command: `deno run --env-file=libs/${normalizedOptions.projectDirectory}/.env --allow-env --allow-net --allow-read ${normalizedOptions.sourceRoot}/index.ts`,\n },\n };\n return projectJson;\n });\n }\n\n //TODO: Change the following to update the manifest in the virtual Tree - not on the file system.\n const project = new Project({\n tsConfigFilePath: `${getWorkspaceLayout(tree).appsDir}/${normalizedOptions.app}/tsconfig.app.json`,\n });\n\n const manifest = project.getSourceFileOrThrow(manifestPath);\n\n manifest.addImportDeclaration({\n moduleSpecifier: normalizedOptions.importPath,\n defaultImport: normalizedOptions.projectCamelcase,\n });\n\n // Get the default export symbol from the manifest\n const defaultExportSymbol = manifest.getDefaultExportSymbolOrThrow();\n\n // Get the aliased symbol if the default export is an alias\n const aliasedSymbol = defaultExportSymbol.getAliasedSymbol() || defaultExportSymbol;\n\n // Get the declaration of the aliased symbol\n const declaration = aliasedSymbol.getDeclarations()[0];\n\n if (!VariableDeclaration.isVariableDeclaration(declaration)) {\n throw new Error(\"Expected variable declaration\");\n }\n const irisAppManifestObject = declaration.getInitializer()?.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n if (!irisAppManifestObject) {\n throw new Error(`irisAppManifest not exported from the file: ${manifestPath}`);\n }\n // Find the extensions property within the irisAppManifest object\n const extensionsProperty = irisAppManifestObject.getPropertyOrThrow(\"extensions\");\n\n if (extensionsProperty.getKind() === SyntaxKind.PropertyAssignment) {\n const extensionsArray = extensionsProperty.getFirstChildByKindOrThrow(SyntaxKind.ArrayLiteralExpression);\n extensionsArray.addElement(`${normalizedOptions.projectCamelcase}`);\n }\n\n await manifest.save();\n\n if (!serverSideExtensionTypes.includes(irisAppExtensionType)) {\n tree.delete(joinPathFragments(normalizedOptions.projectRoot, \"src\", \"index.ts\"));\n }\n\n updateJson(tree, joinPathFragments(normalizedOptions.projectRoot, \"tsconfig.spec.json\"), tsConfigSpec => {\n // extension-manifest.ts is a build time file, so we only need to include it in the spec file for type/lint checking\n tsConfigSpec.include = [...tsConfigSpec.include, \"extension-manifest.ts\"];\n return tsConfigSpec;\n });\n\n updateFileInTree(tree, joinPathFragments(normalizedOptions.projectRoot, \"jest.config.ts\"), fileContent =>\n addPropertyWithName(fileContent, \"moduleNameMapper\", {\n \"@trackunit/css-core\": \"jest-transform-stub\",\n \"@trackunit/ui-icons/icons-sprite-mini.svg\": \"jest-transform-stub\",\n \"@trackunit/ui-icons/icons-sprite-outline.svg\": \"jest-transform-stub\",\n \"@trackunit/ui-icons/icons-sprite-solid.svg\": \"jest-transform-stub\",\n \"@trackunit/ui-icons/icons-sprite-micro.svg\": \"jest-transform-stub\",\n })\n );\n\n await formatFiles(tree);\n installPackagesTask(tree, true);\n return () => {\n // eslint-disable-next-line no-console\n console.log(\"🥳 Successfully created an app extensions and it is already added to the Iris App!\");\n };\n};\nconst updateAppName = async (tree: Tree, options: IrisAppExtensionGeneratorSchema) => {\n if (!options.app) {\n const folders = fs\n .readdirSync(getWorkspaceLayout(tree).appsDir, { withFileTypes: true })\n .filter(item => item.isDirectory());\n\n const tileApps: string[] = [];\n\n folders.forEach(folder => {\n const irisAppManifest = fs\n .readdirSync(`${getWorkspaceLayout(tree).appsDir}/${folder.name}`, { withFileTypes: true })\n .find(item => item.name === \"iris-app-manifest.ts\");\n\n if (irisAppManifest) {\n tileApps.push(folder.name);\n } else {\n const subFolders = fs\n .readdirSync(path.join(getWorkspaceLayout(tree).appsDir, folder.name), { withFileTypes: true })\n .filter(item => item.isDirectory());\n subFolders.forEach(subFolder => {\n const subDirIrisAppManifest = fs\n .readdirSync(`${getWorkspaceLayout(tree).appsDir}/${folder.name}/${subFolder.name}`, {\n withFileTypes: true,\n })\n .find(item => item.name === \"iris-app-manifest.ts\");\n\n if (subDirIrisAppManifest) {\n tileApps.push(path.join(folder.name, subFolder.name));\n }\n });\n }\n });\n\n if (tileApps.length === 1) {\n options.app = tileApps[0] || \"<Missing iris app name>\";\n } else if (tileApps.length === 0) {\n throw new Error(\"Please add an iris-app using: nx g @trackunit/iris-app:create \");\n } else {\n const promptObject = {\n name: \"app\",\n message: \"Select the iris app that this extension should belong to:\",\n type: \"autocomplete\",\n choices: tileApps.map(item => item),\n };\n await prompt(promptObject).then((values: object) => {\n // @ts-ignore - suppressImplicitAnyIndexErrors\n // eslint-disable-next-line @typescript-eslint/dot-notation\n options.app = values[\"app\"];\n });\n }\n }\n return options;\n};\n\nexport default IrisAppExtensionGenerator;\n"]}
@@ -14,5 +14,6 @@ export interface IrisAppExtensionGeneratorSchema {
14
14
  | "ASSET_HOME_EXTENSION"
15
15
  | "ASSET_EVENTS_ACTIONS_EXTENSION"
16
16
  | "LIFECYCLE_EXTENSION"
17
- | "SERVERLESS_FUNCTION_EXTENSION";
17
+ | "SERVERLESS_FUNCTION_EXTENSION"
18
+ | "AI_AGENT_EXTENSION";
18
19
  }