@red-hat-developer-hub/backstage-plugin-catalog-backend-module-model-catalog 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @red-hat-developer-hub/backstage-plugin-catalog-backend-module-model-catalog
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 56c40be: Integrate Backstage discovery and auth services for connector communication.
8
+
9
+ The model-catalog entity provider now resolves the connector base URL via the
10
+ discovery service and authenticates with backend-to-backend service tokens
11
+ instead of unauthenticated direct HTTP calls. The `fromConfig` factory method
12
+ accepts `discovery` and `auth` as additional required dependencies.
13
+
14
+ The techdoc URL reader adds bearer-token authentication when fetching model
15
+ cards and replaces hostname-based bridge URL matching with path-based matching
16
+ that uses the connector plugin ID.
17
+
18
+ ### Patch Changes
19
+
20
+ - c2e3749: bump workspace to 1.52.0
21
+
22
+ ## 0.9.1
23
+
24
+ ### Patch Changes
25
+
26
+ - 4418084: Upgrade workspace to Backstage 1.49.4
27
+
3
28
  ## 0.9.0
4
29
 
5
30
  ### Minor Changes
@@ -1,8 +1,12 @@
1
1
  'use strict';
2
2
 
3
- async function fetchModelCatalogKeys(baseUrl) {
3
+ async function fetchModelCatalogKeys(baseUrl, token) {
4
4
  const res = await fetch(`${baseUrl}/list`, {
5
- method: "GET"
5
+ method: "GET",
6
+ headers: {
7
+ Authorization: `Bearer ${token.token}`,
8
+ "Content-Type": "application/json"
9
+ }
6
10
  });
7
11
  if (!res.ok) {
8
12
  throw new Error(res.statusText);
@@ -10,9 +14,19 @@ async function fetchModelCatalogKeys(baseUrl) {
10
14
  const modelCatalogKeys = await res.json();
11
15
  return modelCatalogKeys.uris;
12
16
  }
13
- async function fetchModelCatalogFromKey(baseUrl, modelCatalogKey) {
14
- const res = await fetch(`${baseUrl}${modelCatalogKey}`, {
15
- method: "GET"
17
+ async function fetchModelCatalogFromKey(baseUrl, modelCatalogKey, token) {
18
+ let tok = "";
19
+ if (token) {
20
+ tok = token?.token;
21
+ }
22
+ const url = `${baseUrl}/models/${modelCatalogKey}`;
23
+ console.log(`Fetching model catalog key ${url}`);
24
+ const res = await fetch(url, {
25
+ method: "GET",
26
+ headers: {
27
+ Authorization: `Bearer ${tok}`,
28
+ "Content-Type": "application/json"
29
+ }
16
30
  });
17
31
  if (!res.ok) {
18
32
  throw new Error(res.statusText);
@@ -1 +1 @@
1
- {"version":3,"file":"BridgeResourceConnector.cjs.js","sources":["../../src/clients/BridgeResourceConnector.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ModelCatalog } from '@redhat-ai-dev/model-catalog-types';\n\n/**\n * ModelCatalogKeys is the object used by the bridge to return the list of keys corresponding to each model catalog entry in the bridge\n * @public\n */\nexport interface ModelCatalogKeys {\n uris: string[];\n}\n\n/**\n * fetchModelCatalogKeys retrieves the keys for each of the model catalog entries in the model catalog bridge service\n * @public\n */\nexport async function fetchModelCatalogKeys(\n baseUrl: string,\n): Promise<string[]> {\n // ToDo: Discover catalog-info endpoint?\n const res = await fetch(`${baseUrl}/list`, {\n method: 'GET',\n });\n\n if (!res.ok) {\n throw new Error(res.statusText);\n }\n\n const modelCatalogKeys: ModelCatalogKeys = await res.json();\n return modelCatalogKeys.uris;\n}\n\n/**\n * fetchModelCatalogFromKey fetches a model catalog JSON object from the bridge based on a given key\n * @public\n */\nexport async function fetchModelCatalogFromKey(\n baseUrl: string,\n modelCatalogKey: string,\n): Promise<ModelCatalog> {\n const res = await fetch(`${baseUrl}${modelCatalogKey}`, {\n method: 'GET',\n });\n\n if (!res.ok) {\n throw new Error(res.statusText);\n }\n\n const modelCatalog: ModelCatalog = await res.json();\n return modelCatalog;\n}\n"],"names":[],"mappings":";;AA6BA,eAAsB,sBACpB,OACmB,EAAA;AAEnB,EAAA,MAAM,GAAM,GAAA,MAAM,KAAM,CAAA,CAAA,EAAG,OAAO,CAAS,KAAA,CAAA,EAAA;AAAA,IACzC,MAAQ,EAAA;AAAA,GACT,CAAA;AAED,EAAI,IAAA,CAAC,IAAI,EAAI,EAAA;AACX,IAAM,MAAA,IAAI,KAAM,CAAA,GAAA,CAAI,UAAU,CAAA;AAAA;AAGhC,EAAM,MAAA,gBAAA,GAAqC,MAAM,GAAA,CAAI,IAAK,EAAA;AAC1D,EAAA,OAAO,gBAAiB,CAAA,IAAA;AAC1B;AAMsB,eAAA,wBAAA,CACpB,SACA,eACuB,EAAA;AACvB,EAAA,MAAM,MAAM,MAAM,KAAA,CAAM,GAAG,OAAO,CAAA,EAAG,eAAe,CAAI,CAAA,EAAA;AAAA,IACtD,MAAQ,EAAA;AAAA,GACT,CAAA;AAED,EAAI,IAAA,CAAC,IAAI,EAAI,EAAA;AACX,IAAM,MAAA,IAAI,KAAM,CAAA,GAAA,CAAI,UAAU,CAAA;AAAA;AAGhC,EAAM,MAAA,YAAA,GAA6B,MAAM,GAAA,CAAI,IAAK,EAAA;AAClD,EAAO,OAAA,YAAA;AACT;;;;;"}
1
+ {"version":3,"file":"BridgeResourceConnector.cjs.js","sources":["../../src/clients/BridgeResourceConnector.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ModelCatalog } from '@redhat-ai-dev/model-catalog-types';\n\n/**\n * ModelCatalogKeys is the object used by the bridge to return the list of keys corresponding to each model catalog entry in the bridge\n * @public\n */\nexport interface ModelCatalogKeys {\n uris: string[];\n}\n\n/**\n * fetchModelCatalogKeys retrieves the keys for each of the model catalog entries in the model catalog bridge service\n * @public\n */\nexport async function fetchModelCatalogKeys(\n baseUrl: string,\n token: { token: string },\n): Promise<string[]> {\n const res = await fetch(`${baseUrl}/list`, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${token.token}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!res.ok) {\n throw new Error(res.statusText);\n }\n\n const modelCatalogKeys: ModelCatalogKeys = await res.json();\n return modelCatalogKeys.uris;\n}\n\n/**\n * fetchModelCatalogFromKey fetches a model catalog JSON object from the bridge based on a given key\n * @public\n */\nexport async function fetchModelCatalogFromKey(\n baseUrl: string,\n modelCatalogKey: string,\n token?: { token: string },\n): Promise<ModelCatalog> {\n let tok = '';\n if (token) {\n tok = token?.token;\n }\n const url = `${baseUrl}/models/${modelCatalogKey}`;\n console.log(`Fetching model catalog key ${url}`);\n const res = await fetch(url, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${tok}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!res.ok) {\n throw new Error(res.statusText);\n }\n\n const modelCatalog: ModelCatalog = await res.json();\n return modelCatalog;\n}\n"],"names":[],"mappings":";;AA6BA,eAAsB,qBAAA,CACpB,SACA,KAAA,EACmB;AACnB,EAAA,MAAM,GAAA,GAAM,MAAM,KAAA,CAAM,CAAA,EAAG,OAAO,CAAA,KAAA,CAAA,EAAS;AAAA,IACzC,MAAA,EAAQ,KAAA;AAAA,IACR,OAAA,EAAS;AAAA,MACP,aAAA,EAAe,CAAA,OAAA,EAAU,KAAA,CAAM,KAAK,CAAA,CAAA;AAAA,MACpC,cAAA,EAAgB;AAAA;AAClB,GACD,CAAA;AAED,EAAA,IAAI,CAAC,IAAI,EAAA,EAAI;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,GAAA,CAAI,UAAU,CAAA;AAAA,EAChC;AAEA,EAAA,MAAM,gBAAA,GAAqC,MAAM,GAAA,CAAI,IAAA,EAAK;AAC1D,EAAA,OAAO,gBAAA,CAAiB,IAAA;AAC1B;AAMA,eAAsB,wBAAA,CACpB,OAAA,EACA,eAAA,EACA,KAAA,EACuB;AACvB,EAAA,IAAI,GAAA,GAAM,EAAA;AACV,EAAA,IAAI,KAAA,EAAO;AACT,IAAA,GAAA,GAAM,KAAA,EAAO,KAAA;AAAA,EACf;AACA,EAAA,MAAM,GAAA,GAAM,CAAA,EAAG,OAAO,CAAA,QAAA,EAAW,eAAe,CAAA,CAAA;AAChD,EAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,2BAAA,EAA8B,GAAG,CAAA,CAAE,CAAA;AAC/C,EAAA,MAAM,GAAA,GAAM,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,IAC3B,MAAA,EAAQ,KAAA;AAAA,IACR,OAAA,EAAS;AAAA,MACP,aAAA,EAAe,UAAU,GAAG,CAAA,CAAA;AAAA,MAC5B,cAAA,EAAgB;AAAA;AAClB,GACD,CAAA;AAED,EAAA,IAAI,CAAC,IAAI,EAAA,EAAI;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,GAAA,CAAI,UAAU,CAAA;AAAA,EAChC;AAEA,EAAA,MAAM,YAAA,GAA6B,MAAM,GAAA,CAAI,IAAA,EAAK;AAClD,EAAA,OAAO,YAAA;AACT;;;;;"}
@@ -2,11 +2,16 @@
2
2
 
3
3
  var catalogModel = require('@backstage/catalog-model');
4
4
 
5
- function GenerateCatalogEntities(modelCatalog, logger) {
5
+ function GenerateCatalogEntities(modelCatalog, svcUrl, logger) {
6
6
  let modelCatalogEntities = [];
7
7
  const models = modelCatalog.models;
8
8
  modelCatalogEntities = modelCatalogEntities.concat(
9
- GenerateModelResourceEntities(models, modelCatalog.modelServer)
9
+ GenerateModelResourceEntities(
10
+ models,
11
+ modelCatalog.modelServer,
12
+ logger,
13
+ svcUrl
14
+ )
10
15
  );
11
16
  if (modelCatalog.modelServer !== void 0) {
12
17
  const modelServer = modelCatalog.modelServer;
@@ -24,7 +29,7 @@ function GenerateCatalogEntities(modelCatalog, logger) {
24
29
  }
25
30
  return modelCatalogEntities;
26
31
  }
27
- function GenerateModelResourceEntities(models, modelServer, logger) {
32
+ function GenerateModelResourceEntities(models, modelServer, logger, svcUrl) {
28
33
  const modelResourceEntities = [];
29
34
  models.forEach((model) => {
30
35
  const modelResourceEntity = {
@@ -77,6 +82,9 @@ function GenerateModelResourceEntities(models, modelServer, logger) {
77
82
  let techdocsUrl = model.annotations[key];
78
83
  techdocsUrl = techdocsUrl.trim();
79
84
  if (techdocsUrl !== "") {
85
+ if (svcUrl !== void 0) {
86
+ techdocsUrl = svcUrl + techdocsUrl;
87
+ }
80
88
  modelResourceEntity.metadata.annotations["backstage.io/techdocs-ref"] = `url:${techdocsUrl}`;
81
89
  }
82
90
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"ModelCatalogGenerator.cjs.js","sources":["../../src/clients/ModelCatalogGenerator.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n ModelCatalog,\n Model,\n ModelServer,\n API,\n} from '@redhat-ai-dev/model-catalog-types';\nimport {\n Entity,\n ComponentEntity,\n ApiEntity,\n ResourceEntity,\n makeValidator,\n} from '@backstage/catalog-model';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nfunction isModelCatalog(o: any): o is ModelCatalog {\n return 'models' in o || 'modelServer' in o;\n}\n\nexport function ParseCatalogJSON(jsonStr: string): ModelCatalog {\n const modelCatalog: ModelCatalog = JSON.parse(jsonStr);\n if (isModelCatalog(modelCatalog)) {\n // do something with now correctly typed object\n return modelCatalog;\n }\n throw new Error(`model catalog JSON in unexpected format: ${jsonStr}`);\n}\n\n// Generate the Backstage catalog entities that correspond to the given model catalog json object\n// Note: These entities will need to have their location and origin location annotations set before ingestion into the catalog\n// An optional logger parameter can be passed if you wish log output from the generator\nexport function GenerateCatalogEntities(\n modelCatalog: ModelCatalog,\n logger?: LoggerService,\n): Entity[] {\n // Generate the Resource entities for the Model(s)\n let modelCatalogEntities: Entity[] = [];\n const models: Model[] = modelCatalog.models;\n modelCatalogEntities = modelCatalogEntities.concat(\n GenerateModelResourceEntities(models, modelCatalog.modelServer, logger),\n );\n\n // Generate the Model Server and Model Server APi entity, if present\n if (modelCatalog.modelServer !== undefined) {\n const modelServer = modelCatalog.modelServer;\n modelCatalogEntities.push(\n GenerateModelServerComponentEntity(\n modelServer,\n modelCatalog.models,\n logger,\n ),\n );\n\n // If there's an exposed API present, generate that entity as well, and update the model server entity accordingly\n if (modelServer.API !== undefined) {\n const api: API = modelServer.API;\n modelCatalogEntities.push(\n GenerateModelServerAPI(api, modelServer, logger),\n );\n }\n }\n\n return modelCatalogEntities;\n}\n\nexport function GenerateModelResourceEntities(\n models: Model[],\n modelServer?: ModelServer,\n logger?: LoggerService,\n): ResourceEntity[] {\n const modelResourceEntities: ResourceEntity[] = [];\n models.forEach(model => {\n const modelResourceEntity: ResourceEntity = {\n apiVersion: 'backstage.io/v1beta1',\n kind: 'Resource',\n metadata: {\n name: sanitizeMetadataName(model.name),\n description: `${model.description}`,\n tags: [],\n links: [],\n },\n spec: {\n owner: `user:${model.owner}`,\n type: 'ai-model',\n },\n };\n\n // Set optional parameters, if present\n if (model.tags !== undefined) {\n modelResourceEntity.metadata.tags = sanitizeTags(model.tags, logger);\n }\n if (model.artifactLocationURL !== undefined) {\n modelResourceEntity.metadata.links?.push({\n title: 'Artifact Location',\n url: `${model.artifactLocationURL}`,\n });\n }\n if (model.howToUseURL !== undefined) {\n modelResourceEntity.metadata.links?.push({\n title: 'How to use',\n url: `${model.howToUseURL}`,\n });\n }\n if (model.license !== undefined) {\n modelResourceEntity.metadata.links?.push({\n title: `License`,\n url: `${model.license}`,\n });\n }\n modelResourceEntity.spec.dependencyOf = [];\n if (modelServer !== undefined) {\n modelResourceEntity.spec.dependencyOf?.push(\n `component:${modelServer.name}`,\n );\n }\n\n // Handle any annotations present on the model resource\n if (model.annotations !== undefined) {\n // Initialize annotations object if needed\n if (modelResourceEntity.metadata.annotations === undefined) {\n modelResourceEntity.metadata.annotations = {};\n }\n\n // Copy all annotations from model to resource entity\n Object.keys(model.annotations).forEach(key => {\n // Special handling for TechDocs annotation\n if (key === 'TechDocs') {\n let techdocsUrl: string = model.annotations![key];\n techdocsUrl = techdocsUrl.trim();\n if (techdocsUrl !== '') {\n modelResourceEntity.metadata.annotations![\n 'backstage.io/techdocs-ref'\n ] = `url:${techdocsUrl}`;\n }\n } else {\n // Copy all other annotations as-is\n modelResourceEntity.metadata.annotations![key] =\n model.annotations![key];\n }\n });\n }\n modelResourceEntities.push(modelResourceEntity);\n });\n\n return modelResourceEntities;\n}\n\nexport function GenerateModelServerComponentEntity(\n modelServer: ModelServer,\n models: Model[],\n logger?: LoggerService,\n): ComponentEntity {\n const modelServerComponent: ComponentEntity = {\n apiVersion: 'backstage.io/v1beta1',\n kind: 'Component',\n metadata: {\n name: sanitizeMetadataName(modelServer.name),\n description: `${modelServer.description}`,\n tags: [],\n links: [],\n },\n spec: {\n type: 'model-server',\n lifecycle: `${modelServer.lifecycle}`,\n owner: `user:${modelServer.owner}`,\n },\n };\n\n // Add the models to the model server as dependants\n modelServerComponent.spec.dependsOn = [];\n models.forEach(model => {\n modelServerComponent.spec.dependsOn?.push(`resource:${model.name}`);\n });\n\n // Configure optional parameters\n // Set optional parameters, if present\n if (modelServer.tags !== undefined) {\n modelServerComponent.metadata.tags = sanitizeTags(modelServer.tags, logger);\n }\n // Add authentication tag\n if (modelServer.authentication === undefined || !modelServer.authentication) {\n modelServerComponent.metadata.tags?.push('auth-not-required');\n } else {\n modelServerComponent.metadata.tags?.push('auth-required');\n }\n modelServerComponent.metadata.links = [];\n if (modelServer.API !== undefined) {\n modelServerComponent.metadata.links.push({\n title: `API`,\n url: `${modelServer.API.url}`,\n });\n modelServerComponent.spec.providesApis = [modelServer.name];\n\n // Copy annotations from API to component metadata if they exist\n if (modelServer.API.annotations !== undefined) {\n if (modelServerComponent.metadata.annotations === undefined) {\n modelServerComponent.metadata.annotations = {};\n }\n // Copy all key-value pairs from API annotations to component annotations\n Object.keys(modelServer.API.annotations).forEach(key => {\n modelServerComponent.metadata.annotations![key] =\n modelServer.API!.annotations![key];\n });\n }\n }\n if (modelServer.homepageURL !== undefined) {\n modelServerComponent.metadata.links.push({\n title: 'Homepage',\n url: `${modelServer.homepageURL}`,\n });\n }\n\n // Copy annotations from modelServer to component metadata if they exist\n if (modelServer.annotations !== undefined) {\n if (modelServerComponent.metadata.annotations === undefined) {\n modelServerComponent.metadata.annotations = {};\n }\n // Copy all key-value pairs from modelServer annotations to component annotations\n Object.keys(modelServer.annotations).forEach(key => {\n modelServerComponent.metadata.annotations![key] =\n modelServer.annotations![key];\n });\n }\n\n return modelServerComponent;\n}\n\nexport function GenerateModelServerAPI(\n api: API,\n modelServer: ModelServer,\n logger?: LoggerService,\n): ApiEntity {\n const modelServerAPIEntity: ApiEntity = {\n apiVersion: `backstage.io/v1beta1`,\n kind: `API`,\n metadata: {\n name: sanitizeMetadataName(modelServer.name),\n tags: [],\n links: [\n {\n url: `${api.url}`,\n title: `API`,\n },\n ],\n },\n spec: {\n type: `${api.type}`,\n owner: `user:${modelServer.owner}`,\n lifecycle: `${modelServer.lifecycle}`,\n definition: `${api.spec}`,\n },\n };\n\n if (api.tags !== undefined) {\n modelServerAPIEntity.metadata.tags = sanitizeTags(api.tags, logger);\n }\n // Add authentication tag\n if (modelServer.authentication === undefined || !modelServer.authentication) {\n modelServerAPIEntity.metadata.tags?.push('auth-not-required');\n } else {\n modelServerAPIEntity.metadata.tags?.push('auth-required');\n }\n return modelServerAPIEntity;\n}\n\nfunction sanitizeMetadataName(modelName: string): string {\n return modelName.replace(/\\s/g, '');\n}\n\nfunction sanitizeTags(tags: string[], logger?: LoggerService): string[] {\n const sanitizedTags: string[] = [];\n tags.forEach(tag => {\n let sanitizedTag: string = tag;\n // Replace whitespace with empty character\n sanitizedTag = sanitizedTag.replace(/\\s/g, '');\n\n // Call the Backstage tag validator and check if the tag conforms\n // If the tag is not valid, skip it\n if (!makeValidator().isValidTag(sanitizedTag)) {\n if (logger !== undefined) {\n logger.error(\n `invalid tag: ${sanitizedTag}. Tags are expected to be less than 63 characters and conform to: ^[a-z0-9:+#]+(\\-[a-z0-9:+#]+)*$`,\n );\n }\n return; /* in typescript a return in a foreach skips to the next iteration */\n }\n sanitizedTags.push(sanitizedTag);\n });\n return sanitizedTags;\n}\n"],"names":["makeValidator"],"mappings":";;;;AA8CgB,SAAA,uBAAA,CACd,cACA,MACU,EAAA;AAEV,EAAA,IAAI,uBAAiC,EAAC;AACtC,EAAA,MAAM,SAAkB,YAAa,CAAA,MAAA;AACrC,EAAA,oBAAA,GAAuB,oBAAqB,CAAA,MAAA;AAAA,IAC1C,6BAA8B,CAAA,MAAA,EAAQ,YAAa,CAAA,WAAmB;AAAA,GACxE;AAGA,EAAI,IAAA,YAAA,CAAa,gBAAgB,MAAW,EAAA;AAC1C,IAAA,MAAM,cAAc,YAAa,CAAA,WAAA;AACjC,IAAqB,oBAAA,CAAA,IAAA;AAAA,MACnB,kCAAA;AAAA,QACE,WAAA;AAAA,QACA,YAAa,CAAA,MAEf;AAAA,KACF;AAGA,IAAI,IAAA,WAAA,CAAY,QAAQ,MAAW,EAAA;AACjC,MAAA,MAAM,MAAW,WAAY,CA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,CAAS,IAAM,EAAA,IAAA,CAAK,mBAAmB,CAAA;AAAA,GACvD,MAAA;AACL,IAAqB,oBAAA,CAAA,QAAA,CAAS,IAAM,EAAA,IAAA,CAAK,eAAe,CAAA;AAAA;AAE1D,EAAO,OAAA,oBAAA;AACT;AAEA,SAAS,qBAAqB,SAA2B,EAAA;AACvD,EAAO,OAAA,SAAA,CAAU,OAAQ,CAAA,KAAA,EAAO,EAAE,CAAA;AACpC;AAEA,SAAS,YAAA,CAAa,MAAgB,MAAkC,EAAA;AACtE,EAAA,MAAM,gBAA0B,EAAC;AACjC,EAAA,IAAA,CAAK,QAAQ,CAAO,GAAA,KAAA;AAClB,IAAA,IAAI,YAAuB,GAAA,GAAA;AAE3B,IAAe,YAAA,GAAA,YAAA,CAAa,OAAQ,CAAA,KAAA,EAAO,EAAE,CAAA;AAI7C,IAAA,IAAI,CAACA,0BAAA,EAAgB,CAAA,UAAA,CAAW,YAAY,CAAG,EAAA;AAM7C,MAAA;AAAA;AAEF,IAAA,aAAA,CAAc,KAAK,YAAY,CAAA;AAAA,GAChC,CAAA;AACD,EAAO,OAAA,aAAA;AACT;;;;;;;"}
1
+ {"version":3,"file":"ModelCatalogGenerator.cjs.js","sources":["../../src/clients/ModelCatalogGenerator.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n ModelCatalog,\n Model,\n ModelServer,\n API,\n} from '@redhat-ai-dev/model-catalog-types';\nimport {\n Entity,\n ComponentEntity,\n ApiEntity,\n ResourceEntity,\n makeValidator,\n} from '@backstage/catalog-model';\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nfunction isModelCatalog(o: any): o is ModelCatalog {\n return 'models' in o || 'modelServer' in o;\n}\n\nexport function ParseCatalogJSON(jsonStr: string): ModelCatalog {\n const modelCatalog: ModelCatalog = JSON.parse(jsonStr);\n if (isModelCatalog(modelCatalog)) {\n // do something with now correctly typed object\n return modelCatalog;\n }\n throw new Error(`model catalog JSON in unexpected format: ${jsonStr}`);\n}\n\n// Generate the Backstage catalog entities that correspond to the given model catalog json object\n// Note: These entities will need to have their location and origin location annotations set before ingestion into the catalog\n// An optional logger parameter can be passed if you wish log output from the generator\nexport function GenerateCatalogEntities(\n modelCatalog: ModelCatalog,\n svcUrl?: string,\n logger?: LoggerService,\n): Entity[] {\n // Generate the Resource entities for the Model(s)\n let modelCatalogEntities: Entity[] = [];\n const models: Model[] = modelCatalog.models;\n modelCatalogEntities = modelCatalogEntities.concat(\n GenerateModelResourceEntities(\n models,\n modelCatalog.modelServer,\n logger,\n svcUrl,\n ),\n );\n\n // Generate the Model Server and Model Server APi entity, if present\n if (modelCatalog.modelServer !== undefined) {\n const modelServer = modelCatalog.modelServer;\n modelCatalogEntities.push(\n GenerateModelServerComponentEntity(\n modelServer,\n modelCatalog.models,\n logger,\n ),\n );\n\n // If there's an exposed API present, generate that entity as well, and update the model server entity accordingly\n if (modelServer.API !== undefined) {\n const api: API = modelServer.API;\n modelCatalogEntities.push(\n GenerateModelServerAPI(api, modelServer, logger),\n );\n }\n }\n\n return modelCatalogEntities;\n}\n\nexport function GenerateModelResourceEntities(\n models: Model[],\n modelServer?: ModelServer,\n logger?: LoggerService,\n svcUrl?: string,\n): ResourceEntity[] {\n const modelResourceEntities: ResourceEntity[] = [];\n models.forEach(model => {\n const modelResourceEntity: ResourceEntity = {\n apiVersion: 'backstage.io/v1beta1',\n kind: 'Resource',\n metadata: {\n name: sanitizeMetadataName(model.name),\n description: `${model.description}`,\n tags: [],\n links: [],\n },\n spec: {\n owner: `user:${model.owner}`,\n type: 'ai-model',\n },\n };\n\n // Set optional parameters, if present\n if (model.tags !== undefined) {\n modelResourceEntity.metadata.tags = sanitizeTags(model.tags, logger);\n }\n if (model.artifactLocationURL !== undefined) {\n modelResourceEntity.metadata.links?.push({\n title: 'Artifact Location',\n url: `${model.artifactLocationURL}`,\n });\n }\n if (model.howToUseURL !== undefined) {\n modelResourceEntity.metadata.links?.push({\n title: 'How to use',\n url: `${model.howToUseURL}`,\n });\n }\n if (model.license !== undefined) {\n modelResourceEntity.metadata.links?.push({\n title: `License`,\n url: `${model.license}`,\n });\n }\n modelResourceEntity.spec.dependencyOf = [];\n if (modelServer !== undefined) {\n modelResourceEntity.spec.dependencyOf?.push(\n `component:${modelServer.name}`,\n );\n }\n\n // Handle any annotations present on the model resource\n if (model.annotations !== undefined) {\n // Initialize annotations object if needed\n if (modelResourceEntity.metadata.annotations === undefined) {\n modelResourceEntity.metadata.annotations = {};\n }\n\n // Copy all annotations from model to resource entity\n Object.keys(model.annotations).forEach(key => {\n // Special handling for TechDocs annotation\n if (key === 'TechDocs') {\n let techdocsUrl: string = model.annotations![key];\n techdocsUrl = techdocsUrl.trim();\n // TODO GGM prepend svc URL\n if (techdocsUrl !== '') {\n if (svcUrl !== undefined) {\n techdocsUrl = svcUrl + techdocsUrl;\n }\n modelResourceEntity.metadata.annotations![\n 'backstage.io/techdocs-ref'\n ] = `url:${techdocsUrl}`;\n }\n } else {\n // Copy all other annotations as-is\n modelResourceEntity.metadata.annotations![key] =\n model.annotations![key];\n }\n });\n }\n modelResourceEntities.push(modelResourceEntity);\n });\n\n return modelResourceEntities;\n}\n\nexport function GenerateModelServerComponentEntity(\n modelServer: ModelServer,\n models: Model[],\n logger?: LoggerService,\n): ComponentEntity {\n const modelServerComponent: ComponentEntity = {\n apiVersion: 'backstage.io/v1beta1',\n kind: 'Component',\n metadata: {\n name: sanitizeMetadataName(modelServer.name),\n description: `${modelServer.description}`,\n tags: [],\n links: [],\n },\n spec: {\n type: 'model-server',\n lifecycle: `${modelServer.lifecycle}`,\n owner: `user:${modelServer.owner}`,\n },\n };\n\n // Add the models to the model server as dependants\n modelServerComponent.spec.dependsOn = [];\n models.forEach(model => {\n modelServerComponent.spec.dependsOn?.push(`resource:${model.name}`);\n });\n\n // Configure optional parameters\n // Set optional parameters, if present\n if (modelServer.tags !== undefined) {\n modelServerComponent.metadata.tags = sanitizeTags(modelServer.tags, logger);\n }\n // Add authentication tag\n if (modelServer.authentication === undefined || !modelServer.authentication) {\n modelServerComponent.metadata.tags?.push('auth-not-required');\n } else {\n modelServerComponent.metadata.tags?.push('auth-required');\n }\n modelServerComponent.metadata.links = [];\n if (modelServer.API !== undefined) {\n modelServerComponent.metadata.links.push({\n title: `API`,\n url: `${modelServer.API.url}`,\n });\n modelServerComponent.spec.providesApis = [modelServer.name];\n\n // Copy annotations from API to component metadata if they exist\n if (modelServer.API.annotations !== undefined) {\n if (modelServerComponent.metadata.annotations === undefined) {\n modelServerComponent.metadata.annotations = {};\n }\n // Copy all key-value pairs from API annotations to component annotations\n Object.keys(modelServer.API.annotations).forEach(key => {\n modelServerComponent.metadata.annotations![key] =\n modelServer.API!.annotations![key];\n });\n }\n }\n if (modelServer.homepageURL !== undefined) {\n modelServerComponent.metadata.links.push({\n title: 'Homepage',\n url: `${modelServer.homepageURL}`,\n });\n }\n\n // Copy annotations from modelServer to component metadata if they exist\n if (modelServer.annotations !== undefined) {\n if (modelServerComponent.metadata.annotations === undefined) {\n modelServerComponent.metadata.annotations = {};\n }\n // Copy all key-value pairs from modelServer annotations to component annotations\n Object.keys(modelServer.annotations).forEach(key => {\n modelServerComponent.metadata.annotations![key] =\n modelServer.annotations![key];\n });\n }\n\n return modelServerComponent;\n}\n\nexport function GenerateModelServerAPI(\n api: API,\n modelServer: ModelServer,\n logger?: LoggerService,\n): ApiEntity {\n const modelServerAPIEntity: ApiEntity = {\n apiVersion: `backstage.io/v1beta1`,\n kind: `API`,\n metadata: {\n name: sanitizeMetadataName(modelServer.name),\n tags: [],\n links: [\n {\n url: `${api.url}`,\n title: `API`,\n },\n ],\n },\n spec: {\n type: `${api.type}`,\n owner: `user:${modelServer.owner}`,\n lifecycle: `${modelServer.lifecycle}`,\n definition: `${api.spec}`,\n },\n };\n\n if (api.tags !== undefined) {\n modelServerAPIEntity.metadata.tags = sanitizeTags(api.tags, logger);\n }\n // Add authentication tag\n if (modelServer.authentication === undefined || !modelServer.authentication) {\n modelServerAPIEntity.metadata.tags?.push('auth-not-required');\n } else {\n modelServerAPIEntity.metadata.tags?.push('auth-required');\n }\n return modelServerAPIEntity;\n}\n\nfunction sanitizeMetadataName(modelName: string): string {\n return modelName.replace(/\\s/g, '');\n}\n\nfunction sanitizeTags(tags: string[], logger?: LoggerService): string[] {\n const sanitizedTags: string[] = [];\n tags.forEach(tag => {\n let sanitizedTag: string = tag;\n // Replace whitespace with empty character\n sanitizedTag = sanitizedTag.replace(/\\s/g, '');\n\n // Call the Backstage tag validator and check if the tag conforms\n // If the tag is not valid, skip it\n if (!makeValidator().isValidTag(sanitizedTag)) {\n if (logger !== undefined) {\n logger.error(\n `invalid tag: ${sanitizedTag}. Tags are expected to be less than 63 characters and conform to: ^[a-z0-9:+#]+(\\-[a-z0-9:+#]+)*$`,\n );\n }\n return; /* in typescript a return in a foreach skips to the next iteration */\n }\n sanitizedTags.push(sanitizedTag);\n });\n return sanitizedTags;\n}\n"],"names":["makeValidator"],"mappings":";;;;AA8CO,SAAS,uBAAA,CACd,YAAA,EACA,MAAA,EACA,MAAA,EACU;AAEV,EAAA,IAAI,uBAAiC,EAAC;AACtC,EAAA,MAAM,SAAkB,YAAA,CAAa,MAAA;AACrC,EAAA,oBAAA,GAAuB,oBAAA,CAAqB,MAAA;AAAA,IAC1C,6BAAA;AAAA,MACE,MAAA;AAAA,MACA,YAAA,CAAa,WAAA;AAAA,MACb,MAAA;AAAA,MACA;AAAA;AACF,GACF;AAGA,EAAA,IAAI,YAAA,CAAa,gBAAgB,MAAA,EAAW;AAC1C,IAAA,MAAM,cAAc,YAAA,CA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  * fetchModelCatalogKeys retrieves the keys for each of the model catalog entries in the model catalog bridge service
20
20
  * @public
21
21
  */
22
- declare function fetchModelCatalogKeys(baseUrl: string): Promise<string[]>;
22
+ declare function fetchModelCatalogKeys(baseUrl: string, token: {
23
+ token: string;
24
+ }): Promise<string[]>;
23
25
  /**
24
26
  * fetchModelCatalogFromKey fetches a model catalog JSON object from the bridge based on a given key
25
27
  * @public
26
28
  */
27
- declare function fetchModelCatalogFromKey(baseUrl: string, modelCatalogKey: string): Promise<ModelCatalog>;
29
+ declare function fetchModelCatalogFromKey(baseUrl: string, modelCatalogKey: string, token?: {
30
+ token: string;
31
+ }): Promise<ModelCatalog>;
28
32
 
29
33
  export { catalogModuleModelCatalogResourceEntityProvider as default, fetchModelCatalogFromKey, fetchModelCatalogKeys };
30
34
  export type { ModelCatalogKeys };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var backendPluginApi = require('@backstage/backend-plugin-api');
4
- var alpha = require('@backstage/plugin-catalog-node/alpha');
4
+ var pluginCatalogNode = require('@backstage/plugin-catalog-node');
5
5
  var ModelCatalogResourceEntityProvider = require('./providers/ModelCatalogResourceEntityProvider.cjs.js');
6
6
 
7
7
  const catalogModuleModelCatalogResourceEntityProvider = backendPluginApi.createBackendModule({
@@ -10,15 +10,17 @@ const catalogModuleModelCatalogResourceEntityProvider = backendPluginApi.createB
10
10
  register(env) {
11
11
  env.registerInit({
12
12
  deps: {
13
- catalog: alpha.catalogProcessingExtensionPoint,
13
+ catalog: pluginCatalogNode.catalogProcessingExtensionPoint,
14
14
  config: backendPluginApi.coreServices.rootConfig,
15
+ discovery: backendPluginApi.coreServices.discovery,
16
+ auth: backendPluginApi.coreServices.auth,
15
17
  logger: backendPluginApi.coreServices.logger,
16
18
  scheduler: backendPluginApi.coreServices.scheduler
17
19
  },
18
- async init({ catalog, config, logger, scheduler }) {
19
- catalog.addEntityProvider(
20
- ModelCatalogResourceEntityProvider.ModelCatalogResourceEntityProvider.fromConfig(
21
- { config, logger },
20
+ async init({ catalog, config, discovery, auth, logger, scheduler }) {
21
+ try {
22
+ const ep = ModelCatalogResourceEntityProvider.ModelCatalogResourceEntityProvider.fromConfig(
23
+ { config, logger, discovery, auth },
22
24
  {
23
25
  schedule: scheduler.createScheduledTaskRunner({
24
26
  frequency: { seconds: 30 },
@@ -26,8 +28,12 @@ const catalogModuleModelCatalogResourceEntityProvider = backendPluginApi.createB
26
28
  }),
27
29
  scheduler
28
30
  }
29
- )
30
- );
31
+ );
32
+ catalog.addEntityProvider(ep);
33
+ } catch (error) {
34
+ console.error(error);
35
+ throw error;
36
+ }
31
37
  }
32
38
  });
33
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\n\nimport { ModelCatalogResourceEntityProvider } from './providers';\n\n/**\n * catalogModuleModelCatalogResourceEntityProvider defines the model catalog entity provider which runs on startup\n *\n * @public\n */\nexport const catalogModuleModelCatalogResourceEntityProvider =\n createBackendModule({\n moduleId: 'catalog-backend-module-model-catalog',\n pluginId: 'catalog',\n register(env) {\n env.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ catalog, config, logger, scheduler }) {\n catalog.addEntityProvider(\n ModelCatalogResourceEntityProvider.fromConfig(\n { config, logger },\n {\n schedule: scheduler.createScheduledTaskRunner({\n frequency: { seconds: 30 },\n timeout: { minutes: 3 },\n }),\n scheduler: scheduler,\n },\n ),\n );\n },\n });\n },\n });\n"],"names":["createBackendModule","catalogProcessingExtensionPoint","coreServices","ModelCatalogResourceEntityProvider"],"mappings":";;;;;;AA4BO,MAAM,kDACXA,oCAAoB,CAAA;AAAA,EAClB,QAAU,EAAA,sCAAA;AAAA,EACV,QAAU,EAAA,SAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,OAAS,EAAAC,qCAAA;AAAA,QACT,QAAQC,6BAAa,CAAA,UAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,WAAWA,6BAAa,CAAA;AAAA,OAC1B;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,SAAS,MAAQ,EAAA,MAAA,EAAQ,WAAa,EAAA;AACjD,QAAQ,OAAA,CAAA,iBAAA;AAAA,UACNC,qEAAmC,CAAA,UAAA;AAAA,YACjC,EAAE,QAAQ,MAAO,EAAA;AAAA,YACjB;AAAA,cACE,QAAA,EAAU,UAAU,yBAA0B,CAAA;AAAA,gBAC5C,SAAA,EAAW,EAAE,OAAA,EAAS,EAAG,EAAA;AAAA,gBACzB,OAAA,EAAS,EAAE,OAAA,EAAS,CAAE;AAAA,eACvB,CAAA;AAAA,cACD;AAAA;AACF;AACF,SACF;AAAA;AACF,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
1
+ {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';\n\nimport { ModelCatalogResourceEntityProvider } from './providers';\n\n/**\n * catalogModuleModelCatalogResourceEntityProvider defines the model catalog entity provider which runs on startup\n *\n * @public\n */\nexport const catalogModuleModelCatalogResourceEntityProvider =\n createBackendModule({\n moduleId: 'catalog-backend-module-model-catalog',\n pluginId: 'catalog',\n register(env) {\n env.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.rootConfig,\n discovery: coreServices.discovery,\n auth: coreServices.auth,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ catalog, config, discovery, auth, logger, scheduler }) {\n try {\n const ep = ModelCatalogResourceEntityProvider.fromConfig(\n { config, logger, discovery, auth },\n {\n schedule: scheduler.createScheduledTaskRunner({\n frequency: { seconds: 30 },\n timeout: { minutes: 3 },\n }),\n scheduler: scheduler,\n },\n );\n catalog.addEntityProvider(ep);\n } catch (error) {\n console.error(error);\n throw error;\n }\n },\n });\n },\n });\n"],"names":["createBackendModule","catalogProcessingExtensionPoint","coreServices","ModelCatalogResourceEntityProvider"],"mappings":";;;;;;AA4BO,MAAM,kDACXA,oCAAA,CAAoB;AAAA,EAClB,QAAA,EAAU,sCAAA;AAAA,EACV,QAAA,EAAU,SAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,OAAA,EAASC,iDAAA;AAAA,QACT,QAAQC,6BAAA,CAAa,UAAA;AAAA,QACrB,WAAWA,6BAAA,CAAa,SAAA;AAAA,QACxB,MAAMA,6BAAA,CAAa,IAAA;AAAA,QACnB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,WAAWA,6BAAA,CAAa;AAAA,OAC1B;AAAA,MACA,MAAM,KAAK,EAAE,OAAA,EAAS,QAAQ,SAAA,EAAW,IAAA,EAAM,MAAA,EAAQ,SAAA,EAAU,EAAG;AAClE,QAAA,IAAI;AACF,UAAA,MAAM,KAAKC,qEAAA,CAAmC,UAAA;AAAA,YAC5C,EAAE,MAAA,EAAQ,MAAA,EAAQ,SAAA,EAAW,IAAA,EAAK;AAAA,YAClC;AAAA,cACE,QAAA,EAAU,UAAU,yBAAA,CAA0B;AAAA,gBAC5C,SAAA,EAAW,EAAE,OAAA,EAAS,EAAA,EAAG;AAAA,gBACzB,OAAA,EAAS,EAAE,OAAA,EAAS,CAAA;AAAE,eACvB,CAAA;AAAA,cACD;AAAA;AACF,WACF;AACA,UAAA,OAAA,CAAQ,kBAAkB,EAAE,CAAA;AAAA,QAC9B,SAAS,KAAA,EAAO;AACd,UAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AACnB,UAAA,MAAM,KAAA;AAAA,QACR;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
@@ -7,9 +7,11 @@ var errors = require('@backstage/errors');
7
7
  var ModelCatalogGenerator = require('../clients/ModelCatalogGenerator.cjs.js');
8
8
 
9
9
  class ModelCatalogResourceEntityProvider {
10
- env;
10
+ name;
11
11
  baseUrl;
12
12
  logger;
13
+ discovery;
14
+ auth;
13
15
  scheduleFn;
14
16
  connection;
15
17
  /**
@@ -17,7 +19,7 @@ class ModelCatalogResourceEntityProvider {
17
19
  * @public
18
20
  */
19
21
  static fromConfig(deps, options) {
20
- const { config: config$1, logger } = deps;
22
+ const { config: config$1, logger, discovery, auth } = deps;
21
23
  const providerConfigs = config.readModelCatalogApiEntityConfigs(config$1);
22
24
  return providerConfigs.map((providerConfig) => {
23
25
  let taskRunner;
@@ -35,14 +37,18 @@ class ModelCatalogResourceEntityProvider {
35
37
  return new ModelCatalogResourceEntityProvider(
36
38
  providerConfig,
37
39
  logger,
40
+ discovery,
41
+ auth,
38
42
  taskRunner
39
43
  );
40
44
  });
41
45
  }
42
46
  /** [1]: Set configuration values passed into the entity provider. Fields are defined in types.ts */
43
- constructor(config, logger, taskRunner) {
44
- this.env = config.id;
47
+ constructor(config, logger, discovery, auth, taskRunner) {
48
+ this.name = config.id;
45
49
  this.baseUrl = config.baseUrl;
50
+ this.discovery = discovery;
51
+ this.auth = auth;
46
52
  this.logger = logger.child({
47
53
  target: this.getProviderName()
48
54
  });
@@ -60,7 +66,7 @@ class ModelCatalogResourceEntityProvider {
60
66
  } catch (error) {
61
67
  if (errors.isError(error)) {
62
68
  this.logger.error(
63
- `Error while syncing resources from Model Catalog ${this.baseUrl}`,
69
+ `Error while syncing resources from Model Catalog ${this.name}`,
64
70
  {
65
71
  // Default Error properties:
66
72
  name: error.name,
@@ -78,7 +84,7 @@ class ModelCatalogResourceEntityProvider {
78
84
  }
79
85
  /** [2]: Model Catalog entity provider must have a unique name */
80
86
  getProviderName() {
81
- return `ModelCatalogResourceEntityProvider:${this.env}`;
87
+ return `ModelCatalogResourceEntityProvider:${this.name}`;
82
88
  }
83
89
  /** [3]: Connect Backstage catalog engine to ModelCatalogEntityProvider */
84
90
  async connect(connection) {
@@ -91,22 +97,33 @@ class ModelCatalogResourceEntityProvider {
91
97
  throw new Error("Not initialized");
92
98
  }
93
99
  this.logger.info(
94
- `Discovering ResourceEntities from Model Server ${this.baseUrl}`
100
+ `Discovering ResourceEntities from Model Server ${this.name}`
95
101
  );
96
- let catalogKeys = await BridgeResourceConnector.fetchModelCatalogKeys(this.baseUrl);
102
+ const svcUrl = await this.discovery.getBaseUrl(this.name);
103
+ let url = this.baseUrl;
104
+ if (svcUrl.length > 0 && url.length === 0) {
105
+ url = svcUrl;
106
+ }
107
+ const backendToken = await this.auth.getPluginRequestToken({
108
+ onBehalfOf: await this.auth.getOwnServiceCredentials(),
109
+ targetPluginId: this.name
110
+ });
111
+ let catalogKeys = await BridgeResourceConnector.fetchModelCatalogKeys(url, backendToken);
97
112
  if (catalogKeys === null || catalogKeys === void 0) {
98
113
  catalogKeys = [];
99
114
  }
100
- let entityList = [];
101
115
  this.logger.debug(`Found ${catalogKeys.length} model catalogs`);
102
116
  this.logger.debug(`Fetched ModelCatalog: ${JSON.stringify(catalogKeys)}`);
103
- await Promise.all(
117
+ const entityList = (await Promise.all(
104
118
  catalogKeys.map(async (key) => {
105
- const catalog = await BridgeResourceConnector.fetchModelCatalogFromKey(this.baseUrl, key);
106
- const catalogEntities = ModelCatalogGenerator.GenerateCatalogEntities(catalog);
107
- entityList = entityList.concat(catalogEntities);
119
+ const catalog = await BridgeResourceConnector.fetchModelCatalogFromKey(
120
+ url,
121
+ key,
122
+ backendToken
123
+ );
124
+ return ModelCatalogGenerator.GenerateCatalogEntities(catalog, url);
108
125
  })
109
- );
126
+ )).flat();
110
127
  entityList.forEach((entity) => {
111
128
  if (entity.metadata.annotations === void 0) {
112
129
  entity.metadata.annotations = {
@@ -1 +1 @@
1
- {"version":3,"file":"ModelCatalogResourceEntityProvider.cjs.js","sources":["../../src/providers/ModelCatalogResourceEntityProvider.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type {\n LoggerService,\n SchedulerService,\n SchedulerServiceTaskRunner,\n} from '@backstage/backend-plugin-api';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-node';\nimport {\n ANNOTATION_LOCATION,\n ANNOTATION_ORIGIN_LOCATION,\n Entity,\n} from '@backstage/catalog-model';\n\nimport {\n fetchModelCatalogFromKey,\n fetchModelCatalogKeys,\n} from '../clients/BridgeResourceConnector';\nimport { ModelCatalogConfig } from './types';\nimport { readModelCatalogApiEntityConfigs } from './config';\nimport type { Config } from '@backstage/config';\nimport { InputError, isError } from '@backstage/errors';\nimport { GenerateCatalogEntities } from '../clients/ModelCatalogGenerator';\n/**\n * Provides entities from the model catalog service, allowing models and model servers to be imported into RHDH\n *\n * @public\n */\nexport class ModelCatalogResourceEntityProvider implements EntityProvider {\n private readonly env: string;\n private readonly baseUrl: string;\n private readonly logger: LoggerService;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n /**\n * Fetches the configuration values specified for the entity provider in the app-config.yaml\n * @public\n */\n static fromConfig(\n deps: {\n config: Config;\n logger: LoggerService;\n },\n options:\n | { schedule: SchedulerServiceTaskRunner }\n | { scheduler: SchedulerService },\n ): ModelCatalogResourceEntityProvider[] {\n const { config, logger } = deps;\n\n const providerConfigs = readModelCatalogApiEntityConfigs(config);\n\n return providerConfigs.map(providerConfig => {\n let taskRunner;\n if ('scheduler' in options && providerConfig.schedule) {\n taskRunner = options.scheduler.createScheduledTaskRunner(\n providerConfig.schedule,\n );\n } else if ('schedule' in options) {\n taskRunner = options.schedule;\n } else {\n throw new InputError(\n `No schedule provided via config for ModelCatalogResourceEntityProvider:${providerConfig.id}.`,\n );\n }\n\n return new ModelCatalogResourceEntityProvider(\n providerConfig,\n logger,\n taskRunner,\n );\n });\n }\n /** [1]: Set configuration values passed into the entity provider. Fields are defined in types.ts */\n private constructor(\n config: ModelCatalogConfig,\n logger: LoggerService,\n taskRunner: SchedulerServiceTaskRunner,\n ) {\n this.env = config.id;\n this.baseUrl = config.baseUrl;\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(taskRunner);\n }\n\n /** Configure the schedule function and its logger */\n createScheduleFn(\n taskRunner: SchedulerServiceTaskRunner,\n ): () => Promise<void> {\n return async () => {\n const taskId = `${this.getProviderName()}:run`;\n return taskRunner.run({\n id: taskId,\n fn: async () => {\n try {\n await this.run();\n } catch (error) {\n if (isError(error)) {\n // Ensure that we don't log any sensitive internal data:\n this.logger.error(\n `Error while syncing resources from Model Catalog ${this.baseUrl}`,\n {\n // Default Error properties:\n name: error.name,\n message: error.message,\n stack: error.stack,\n // Additional status code if available:\n status: (error.response as { status?: string })?.status,\n },\n );\n }\n }\n },\n });\n };\n }\n\n /** [2]: Model Catalog entity provider must have a unique name */\n getProviderName(): string {\n return `ModelCatalogResourceEntityProvider:${this.env}`;\n }\n\n /** [3]: Connect Backstage catalog engine to ModelCatalogEntityProvider */\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n /** [4]: Define the function that the entity provider will execute on a set schedule */\n async run(): Promise<void> {\n if (!this.connection) {\n throw new Error('Not initialized');\n }\n this.logger.info(\n `Discovering ResourceEntities from Model Server ${this.baseUrl}`,\n );\n\n /** [5]: Fetch the model catalog keys from the bridge and fetch the corresponding catalog entries. */\n let catalogKeys = await fetchModelCatalogKeys(this.baseUrl);\n // If no models are registered yet, the catalogKeys array may be null, so handle it by setting it to be an emptyList\n if (catalogKeys === null || catalogKeys === undefined) {\n catalogKeys = [];\n }\n let entityList: Entity[] = [];\n this.logger.debug(`Found ${catalogKeys.length} model catalogs`);\n this.logger.debug(`Fetched ModelCatalog: ${JSON.stringify(catalogKeys)}`);\n\n await Promise.all(\n catalogKeys.map(async key => {\n const catalog = await fetchModelCatalogFromKey(this.baseUrl, key);\n const catalogEntities = GenerateCatalogEntities(catalog);\n entityList = entityList.concat(catalogEntities);\n }),\n );\n\n entityList.forEach(entity => {\n if (entity.metadata.annotations === undefined) {\n entity.metadata.annotations = {\n [ANNOTATION_LOCATION]: this.getProviderName(),\n [ANNOTATION_ORIGIN_LOCATION]: this.getProviderName(),\n };\n } else {\n entity.metadata.annotations[ANNOTATION_LOCATION] =\n this.getProviderName();\n entity.metadata.annotations[ANNOTATION_ORIGIN_LOCATION] =\n this.getProviderName();\n }\n });\n this.logger.debug(`Found ${entityList.length} entities`);\n this.logger.debug(`Fetched Entities: ${JSON.stringify(entityList)}`);\n /** [6]: Add/update the catalog entities that correspond to the models */\n await this.connection.applyMutation({\n type: 'full',\n entities: entityList.map(entity => ({\n entity,\n locationKey: this.getProviderName(),\n })),\n });\n }\n\n /* private getEntityLocationRef(entity: LocationEntityV1alpha1): string {\n const ref = entity.metadata.annotations?.[ANNOTATION_LOCATION];\n if (!ref) {\n throw new InputError(\n `Entity '${entity.metadata.name}' does not have the annotation ${ANNOTATION_LOCATION}`,\n );\n }\n return ref;\n }\n\n private getLocationEntity(\n urlStr: string,\n ): { entity: LocationEntityV1alpha1; locationKey: string }[] {\n const entity = locationSpecToLocationEntity({\n location: {\n type: 'rhdh-rhoai-bridge',\n target: urlStr,\n },\n });\n const locationKey = this.getEntityLocationRef(entity);\n return [{ entity, locationKey }];\n }*/\n\n /* private convertModelNameToEntityName(modelName: string): string {\n return modelName.replaceAll(/\\:/g, '-');\n }\n\n private convertModeServerName(modelName: string): string {\n return modelName.replaceAll(/\\s/g, '-').toLowerCase();\n }\n\n private buildResourceEntityFromModelEndpoint(\n models: ModelList,\n modelServerName: string,\n ): ResourceEntity[] {\n const modelResources: ResourceEntity[] = [];\n models.data.forEach(model => {\n const modelResourceEntity: ResourceEntity = {\n kind: 'Resource',\n apiVersion: 'backstage.io/v1alpha1',\n metadata: {\n annotations: {\n [ANNOTATION_LOCATION]: this.getProviderName(),\n [ANNOTATION_ORIGIN_LOCATION]: this.getProviderName(),\n },\n name: `${this.convertModelNameToEntityName(model.id)}`,\n description: `STUB description`,\n links: [\n {\n url: `${this.baseUrl}`,\n title: 'Model API',\n },\n ],\n },\n spec: {\n type: `ai-model`,\n owner: `${this.owner}`,\n dependencyOf: [`component:${modelServerName}`],\n ...(this.system && { system: `${this.system}` }),\n },\n };\n modelResources.push(modelResourceEntity);\n });\n return modelResources;\n }\n\n private buildComponentEntityFromModelEndpoint(\n modelServerName: string,\n ): ComponentEntity {\n const modelServerComponent: ComponentEntity = {\n kind: 'Component',\n apiVersion: 'backstage.io/v1alpha1',\n metadata: {\n annotations: {\n [ANNOTATION_LOCATION]: this.getProviderName(),\n [ANNOTATION_ORIGIN_LOCATION]: this.getProviderName(),\n },\n name: `${this.convertModeServerName(modelServerName)}`,\n description: `${this.name}`,\n links: [\n {\n url: `${this.baseUrl}`,\n title: 'Model Server API',\n },\n ],\n },\n spec: {\n type: `model-server`,\n lifecycle: 'production',\n owner: `${this.owner}`,\n ...(this.system && { system: `${this.system}` }),\n },\n };\n\n return modelServerComponent;\n }*/\n}\n"],"names":["config","readModelCatalogApiEntityConfigs","InputError","isError","fetchModelCatalogKeys","fetchModelCatalogFromKey","GenerateCatalogEntities","ANNOTATION_LOCATION","ANNOTATION_ORIGIN_LOCATION"],"mappings":";;;;;;;;AA4CO,MAAM,kCAA6D,CAAA;AAAA,EACvD,GAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACT,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,OAAO,UACL,CAAA,IAAA,EAIA,OAGsC,EAAA;AACtC,IAAM,MAAA,UAAEA,QAAQ,EAAA,MAAA,EAAW,GAAA,IAAA;AAE3B,IAAM,MAAA,eAAA,GAAkBC,wCAAiCD,QAAM,CAAA;AAE/D,IAAO,OAAA,eAAA,CAAgB,IAAI,CAAkB,cAAA,KAAA;AAC3C,MAAI,IAAA,UAAA;AACJ,MAAI,IAAA,WAAA,IAAe,OAAW,IAAA,cAAA,CAAe,QAAU,EAAA;AACrD,QAAA,UAAA,GAAa,QAAQ,SAAU,CAAA,yBAAA;AAAA,UAC7B,cAAe,CAAA;AAAA,SACjB;AAAA,OACF,MAAA,IAAW,cAAc,OAAS,EAAA;AAChC,QAAA,UAAA,GAAa,OAAQ,CAAA,QAAA;AAAA,OAChB,MAAA;AACL,QAAA,MAAM,IAAIE,iBAAA;AAAA,UACR,CAAA,uEAAA,EAA0E,eAAe,EAAE,CAAA,CAAA;AAAA,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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkGF;;;;"}
1
+ {"version":3,"file":"ModelCatalogResourceEntityProvider.cjs.js","sources":["../../src/providers/ModelCatalogResourceEntityProvider.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type {\n AuthService,\n DiscoveryService,\n LoggerService,\n SchedulerService,\n SchedulerServiceTaskRunner,\n} from '@backstage/backend-plugin-api';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-node';\nimport {\n ANNOTATION_LOCATION,\n ANNOTATION_ORIGIN_LOCATION,\n} from '@backstage/catalog-model';\n\nimport {\n fetchModelCatalogFromKey,\n fetchModelCatalogKeys,\n} from '../clients/BridgeResourceConnector';\nimport { ModelCatalogConfig } from './types';\nimport { readModelCatalogApiEntityConfigs } from './config';\nimport type { Config } from '@backstage/config';\nimport { InputError, isError } from '@backstage/errors';\nimport { GenerateCatalogEntities } from '../clients/ModelCatalogGenerator';\n/**\n * Provides entities from the model catalog service, allowing models and model servers to be imported into RHDH\n *\n * @public\n */\nexport class ModelCatalogResourceEntityProvider implements EntityProvider {\n private readonly name: string;\n private readonly baseUrl: string;\n private readonly logger: LoggerService;\n private readonly discovery: DiscoveryService;\n private readonly auth: AuthService;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n /**\n * Fetches the configuration values specified for the entity provider in the app-config.yaml\n * @public\n */\n static fromConfig(\n deps: {\n config: Config;\n logger: LoggerService;\n discovery: DiscoveryService;\n auth: AuthService;\n },\n options:\n | { schedule: SchedulerServiceTaskRunner }\n | { scheduler: SchedulerService },\n ): ModelCatalogResourceEntityProvider[] {\n const { config, logger, discovery, auth } = deps;\n\n const providerConfigs = readModelCatalogApiEntityConfigs(config);\n\n return providerConfigs.map(providerConfig => {\n let taskRunner;\n if ('scheduler' in options && providerConfig.schedule) {\n taskRunner = options.scheduler.createScheduledTaskRunner(\n providerConfig.schedule,\n );\n } else if ('schedule' in options) {\n taskRunner = options.schedule;\n } else {\n throw new InputError(\n `No schedule provided via config for ModelCatalogResourceEntityProvider:${providerConfig.id}.`,\n );\n }\n\n return new ModelCatalogResourceEntityProvider(\n providerConfig,\n logger,\n discovery,\n auth,\n taskRunner,\n );\n });\n }\n /** [1]: Set configuration values passed into the entity provider. Fields are defined in types.ts */\n private constructor(\n config: ModelCatalogConfig,\n logger: LoggerService,\n discovery: DiscoveryService,\n auth: AuthService,\n taskRunner: SchedulerServiceTaskRunner,\n ) {\n this.name = config.id;\n this.baseUrl = config.baseUrl;\n this.discovery = discovery;\n this.auth = auth;\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(taskRunner);\n }\n\n /** Configure the schedule function and its logger */\n createScheduleFn(\n taskRunner: SchedulerServiceTaskRunner,\n ): () => Promise<void> {\n return async () => {\n const taskId = `${this.getProviderName()}:run`;\n return taskRunner.run({\n id: taskId,\n fn: async () => {\n try {\n await this.run();\n } catch (error) {\n if (isError(error)) {\n // Ensure that we don't log any sensitive internal data:\n this.logger.error(\n `Error while syncing resources from Model Catalog ${this.name}`,\n {\n // Default Error properties:\n name: error.name,\n message: error.message,\n stack: error.stack,\n // Additional status code if available:\n status: (error.response as { status?: string })?.status,\n },\n );\n }\n }\n },\n });\n };\n }\n\n /** [2]: Model Catalog entity provider must have a unique name */\n getProviderName(): string {\n return `ModelCatalogResourceEntityProvider:${this.name}`;\n }\n\n /** [3]: Connect Backstage catalog engine to ModelCatalogEntityProvider */\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n /** [4]: Define the function that the entity provider will execute on a set schedule */\n async run(): Promise<void> {\n if (!this.connection) {\n throw new Error('Not initialized');\n }\n this.logger.info(\n `Discovering ResourceEntities from Model Server ${this.name}`,\n );\n\n /** [5]: Fetch the model catalog keys from the bridge and fetch the corresponding catalog entries. */\n // the api docs for this method says to run it each time vs. once during init, as the URL can change\n const svcUrl = await this.discovery.getBaseUrl(this.name);\n let url = this.baseUrl;\n if (svcUrl.length > 0 && url.length === 0) {\n url = svcUrl;\n }\n const backendToken = await this.auth.getPluginRequestToken({\n onBehalfOf: await this.auth.getOwnServiceCredentials(),\n targetPluginId: this.name,\n });\n let catalogKeys = await fetchModelCatalogKeys(url, backendToken);\n // If no models are registered yet, the catalogKeys array may be null, so handle it by setting it to be an emptyList\n if (catalogKeys === null || catalogKeys === undefined) {\n catalogKeys = [];\n }\n this.logger.debug(`Found ${catalogKeys.length} model catalogs`);\n this.logger.debug(`Fetched ModelCatalog: ${JSON.stringify(catalogKeys)}`);\n\n const entityList = (\n await Promise.all(\n catalogKeys.map(async key => {\n const catalog = await fetchModelCatalogFromKey(\n url,\n key,\n backendToken,\n );\n return GenerateCatalogEntities(catalog, url);\n }),\n )\n ).flat();\n\n entityList.forEach(entity => {\n if (entity.metadata.annotations === undefined) {\n entity.metadata.annotations = {\n [ANNOTATION_LOCATION]: this.getProviderName(),\n [ANNOTATION_ORIGIN_LOCATION]: this.getProviderName(),\n };\n } else {\n entity.metadata.annotations[ANNOTATION_LOCATION] =\n this.getProviderName();\n entity.metadata.annotations[ANNOTATION_ORIGIN_LOCATION] =\n this.getProviderName();\n }\n });\n this.logger.debug(`Found ${entityList.length} entities`);\n this.logger.debug(`Fetched Entities: ${JSON.stringify(entityList)}`);\n /** [6]: Add/update the catalog entities that correspond to the models */\n await this.connection.applyMutation({\n type: 'full',\n entities: entityList.map(entity => ({\n entity,\n locationKey: this.getProviderName(),\n })),\n });\n }\n\n /* private getEntityLocationRef(entity: LocationEntityV1alpha1): string {\n const ref = entity.metadata.annotations?.[ANNOTATION_LOCATION];\n if (!ref) {\n throw new InputError(\n `Entity '${entity.metadata.name}' does not have the annotation ${ANNOTATION_LOCATION}`,\n );\n }\n return ref;\n }\n\n private getLocationEntity(\n urlStr: string,\n ): { entity: LocationEntityV1alpha1; locationKey: string }[] {\n const entity = locationSpecToLocationEntity({\n location: {\n type: 'rhdh-rhoai-bridge',\n target: urlStr,\n },\n });\n const locationKey = this.getEntityLocationRef(entity);\n return [{ entity, locationKey }];\n }*/\n\n /* private convertModelNameToEntityName(modelName: string): string {\n return modelName.replaceAll(/\\:/g, '-');\n }\n\n private convertModeServerName(modelName: string): string {\n return modelName.replaceAll(/\\s/g, '-').toLowerCase();\n }\n\n private buildResourceEntityFromModelEndpoint(\n models: ModelList,\n modelServerName: string,\n ): ResourceEntity[] {\n const modelResources: ResourceEntity[] = [];\n models.data.forEach(model => {\n const modelResourceEntity: ResourceEntity = {\n kind: 'Resource',\n apiVersion: 'backstage.io/v1alpha1',\n metadata: {\n annotations: {\n [ANNOTATION_LOCATION]: this.getProviderName(),\n [ANNOTATION_ORIGIN_LOCATION]: this.getProviderName(),\n },\n name: `${this.convertModelNameToEntityName(model.id)}`,\n description: `STUB description`,\n links: [\n {\n url: `${this.baseUrl}`,\n title: 'Model API',\n },\n ],\n },\n spec: {\n type: `ai-model`,\n owner: `${this.owner}`,\n dependencyOf: [`component:${modelServerName}`],\n ...(this.system && { system: `${this.system}` }),\n },\n };\n modelResources.push(modelResourceEntity);\n });\n return modelResources;\n }\n\n private buildComponentEntityFromModelEndpoint(\n modelServerName: string,\n ): ComponentEntity {\n const modelServerComponent: ComponentEntity = {\n kind: 'Component',\n apiVersion: 'backstage.io/v1alpha1',\n metadata: {\n annotations: {\n [ANNOTATION_LOCATION]: this.getProviderName(),\n [ANNOTATION_ORIGIN_LOCATION]: this.getProviderName(),\n },\n name: `${this.convertModeServerName(modelServerName)}`,\n description: `${this.name}`,\n links: [\n {\n url: `${this.baseUrl}`,\n title: 'Model Server API',\n },\n ],\n },\n spec: {\n type: `model-server`,\n lifecycle: 'production',\n owner: `${this.owner}`,\n ...(this.system && { system: `${this.system}` }),\n },\n };\n\n return modelServerComponent;\n }*/\n}\n"],"names":["config","readModelCatalogApiEntityConfigs","InputError","isError","fetchModelCatalogKeys","fetchModelCatalogFromKey","GenerateCatalogEntities","ANNOTATION_LOCATION","ANNOTATION_ORIGIN_LOCATION"],"mappings":";;;;;;;;AA6CO,MAAM,kCAAA,CAA6D;AAAA,EACvD,IAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,SAAA;AAAA,EACA,IAAA;AAAA,EACA,UAAA;AAAA,EACT,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,OAAO,UAAA,CACL,IAAA,EAMA,OAAA,EAGsC;AACtC,IAAA,MAAM,UAAEA,QAAA,EAAQ,MAAA,EAAQ,SAAA,EAAW,MAAK,GAAI,IAAA;AAE5C,IAAA,MAAM,eAAA,GAAkBC,wCAAiCD,QAAM,CAAA;AAE/D,IAAA,OAAO,eAAA,CAAgB,IAAI,CAAA,cAAA,KAAkB;AAC3C,MAAA,IAAI,UAAA;AACJ,MAAA,IAAI,WAAA,IAAe,OAAA,IAAW,cAAA,CAAe,QAAA,EAAU;AACrD,QAAA,UAAA,GAAa,QAAQ,SAAA,CAAU,yBAAA;AAAA,UAC7B,cAAA,CAAe;AAAA,SACjB;AAAA,MACF,CAAA,MAAA,IAAW,cAAc,OAAA,EAAS;AAChC,QAAA,UAAA,GAAa,OAAA,CAAQ,QAAA;AAAA,MACvB,CAAA,MAAO;AACL,QAAA,MAAM,IAAIE,iBAAA;AAAA,UACR,CAAA,u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AK,OAAO,KAAA,CAAM,CAAA,kBAAA,EAAqB,KAAK,SAAA,CAAU,UAAU,CAAC,CAAA,CAAE,CAAA;AAEnE,IAAA,MAAM,IAAA,CAAK,WAAW,aAAA,CAAc;AAAA,MAClC,IAAA,EAAM,MAAA;AAAA,MACN,QAAA,EAAU,UAAA,CAAW,GAAA,CAAI,CAAA,MAAA,MAAW;AAAA,QAClC,MAAA;AAAA,QACA,WAAA,EAAa,KAAK,eAAA;AAAgB,OACpC,CAAE;AAAA,KACH,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkGF;;;;"}
@@ -14,7 +14,10 @@ function readModelCatalogApiEntityConfigs(config) {
14
14
  );
15
15
  }
16
16
  function readModelCatalogApiEntityConfig(id, config) {
17
- const baseUrl = config.getString("baseUrl");
17
+ let baseUrl = "";
18
+ if (config.has("baseUrl")) {
19
+ baseUrl = config.getString("baseUrl");
20
+ }
18
21
  const schedule = config.has("schedule") ? backendPluginApi.readSchedulerServiceTaskScheduleDefinitionFromConfig(
19
22
  config.getConfig("schedule")
20
23
  ) : void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"config.cjs.js","sources":["../../src/providers/config.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { readSchedulerServiceTaskScheduleDefinitionFromConfig } from '@backstage/backend-plugin-api';\nimport type { Config } from '@backstage/config';\n\nimport type { ModelCatalogConfig } from './types';\n\n/**\n * readModelCatalogApiEntityConfigs reads the configuration for the ModelCatalog provider\n *\n * @public\n */\nexport function readModelCatalogApiEntityConfigs(\n config: Config,\n): ModelCatalogConfig[] {\n const providerConfigs = config.getOptionalConfig(\n 'catalog.providers.modelCatalog',\n );\n if (!providerConfigs) {\n return [];\n }\n return providerConfigs\n .keys()\n .map(id =>\n readModelCatalogApiEntityConfig(id, providerConfigs.getConfig(id)),\n );\n}\n\nfunction readModelCatalogApiEntityConfig(\n id: string,\n config: Config,\n): ModelCatalogConfig {\n const baseUrl = config.getString('baseUrl');\n\n const schedule = config.has('schedule')\n ? readSchedulerServiceTaskScheduleDefinitionFromConfig(\n config.getConfig('schedule'),\n )\n : undefined;\n\n return {\n id,\n baseUrl,\n schedule,\n };\n}\n"],"names":["readSchedulerServiceTaskScheduleDefinitionFromConfig"],"mappings":";;;;AAyBO,SAAS,iCACd,MACsB,EAAA;AACtB,EAAA,MAAM,kBAAkB,MAAO,CAAA,iBAAA;AAAA,IAC7B;AAAA,GACF;AACA,EAAA,IAAI,CAAC,eAAiB,EAAA;AACpB,IAAA,OAAO,EAAC;AAAA;AAEV,EAAO,OAAA,eAAA,CACJ,MACA,CAAA,GAAA;AAAA,IAAI,QACH,+BAAgC,CAAA,EAAA,EAAI,eAAgB,CAAA,SAAA,CAAU,EAAE,CAAC;AAAA,GACnE;AACJ;AAEA,SAAS,+BAAA,CACP,IACA,MACoB,EAAA;AACpB,EAAM,MAAA,OAAA,GAAU,MAAO,CAAA,SAAA,CAAU,SAAS,CAAA;AAE1C,EAAA,MAAM,QAAW,GAAA,MAAA,CAAO,GAAI,CAAA,UAAU,CAClC,GAAAA,qEAAA;AAAA,IACE,MAAA,CAAO,UAAU,UAAU;AAAA,GAE7B,GAAA,MAAA;AAEJ,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"config.cjs.js","sources":["../../src/providers/config.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { readSchedulerServiceTaskScheduleDefinitionFromConfig } from '@backstage/backend-plugin-api';\nimport type { Config } from '@backstage/config';\n\nimport type { ModelCatalogConfig } from './types';\n\n/**\n * readModelCatalogApiEntityConfigs reads the configuration for the ModelCatalog provider\n *\n * @public\n */\nexport function readModelCatalogApiEntityConfigs(\n config: Config,\n): ModelCatalogConfig[] {\n const providerConfigs = config.getOptionalConfig(\n 'catalog.providers.modelCatalog',\n );\n if (!providerConfigs) {\n return [];\n }\n return providerConfigs\n .keys()\n .map(id =>\n readModelCatalogApiEntityConfig(id, providerConfigs.getConfig(id)),\n );\n}\n\nfunction readModelCatalogApiEntityConfig(\n id: string,\n config: Config,\n): ModelCatalogConfig {\n let baseUrl = '';\n if (config.has('baseUrl')) {\n baseUrl = config.getString('baseUrl');\n }\n\n const schedule = config.has('schedule')\n ? readSchedulerServiceTaskScheduleDefinitionFromConfig(\n config.getConfig('schedule'),\n )\n : undefined;\n\n return {\n id,\n baseUrl,\n schedule,\n };\n}\n"],"names":["readSchedulerServiceTaskScheduleDefinitionFromConfig"],"mappings":";;;;AAyBO,SAAS,iCACd,MAAA,EACsB;AACtB,EAAA,MAAM,kBAAkB,MAAA,CAAO,iBAAA;AAAA,IAC7B;AAAA,GACF;AACA,EAAA,IAAI,CAAC,eAAA,EAAiB;AACpB,IAAA,OAAO,EAAC;AAAA,EACV;AACA,EAAA,OAAO,eAAA,CACJ,MAAK,CACL,GAAA;AAAA,IAAI,QACH,+BAAA,CAAgC,EAAA,EAAI,eAAA,CAAgB,SAAA,CAAU,EAAE,CAAC;AAAA,GACnE;AACJ;AAEA,SAAS,+BAAA,CACP,IACA,MAAA,EACoB;AACpB,EAAA,IAAI,OAAA,GAAU,EAAA;AACd,EAAA,IAAI,MAAA,CAAO,GAAA,CAAI,SAAS,CAAA,EAAG;AACzB,IAAA,OAAA,GAAU,MAAA,CAAO,UAAU,SAAS,CAAA;AAAA,EACtC;AAEA,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,GAAA,CAAI,UAAU,CAAA,GAClCA,qEAAA;AAAA,IACE,MAAA,CAAO,UAAU,UAAU;AAAA,GAC7B,GACA,MAAA;AAEJ,EAAA,OAAO;AAAA,IACL,EAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@red-hat-developer-hub/backstage-plugin-catalog-backend-module-model-catalog",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The model-catalog backend module for the catalog plugin.",
6
6
  "main": "dist/index.cjs.js",
@@ -36,21 +36,21 @@
36
36
  "postpack": "backstage-cli package postpack"
37
37
  },
38
38
  "dependencies": {
39
- "@backstage/backend-plugin-api": "^1.5.0",
40
- "@backstage/catalog-client": "^1.12.1",
41
- "@backstage/catalog-model": "^1.7.6",
42
- "@backstage/errors": "^1.2.7",
43
- "@backstage/plugin-catalog-backend": "^3.2.0",
44
- "@backstage/plugin-catalog-common": "^1.1.7",
45
- "@backstage/plugin-catalog-node": "^1.20.0",
39
+ "@backstage/backend-plugin-api": "^1.9.2",
40
+ "@backstage/catalog-client": "^1.16.0",
41
+ "@backstage/catalog-model": "^1.9.0",
42
+ "@backstage/errors": "^1.3.1",
43
+ "@backstage/plugin-catalog-backend": "^3.8.0",
44
+ "@backstage/plugin-catalog-common": "^1.1.10",
45
+ "@backstage/plugin-catalog-node": "^2.2.2",
46
46
  "@redhat-ai-dev/model-catalog-types": "^1.1.0",
47
47
  "js-yaml": "^4.1.0",
48
48
  "stream": "^0.0.3",
49
49
  "yaml": "^2.7.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@backstage/backend-test-utils": "^1.10.1",
53
- "@backstage/cli": "^0.34.5"
52
+ "@backstage/backend-test-utils": "^1.11.4",
53
+ "@backstage/cli": "^0.36.3"
54
54
  },
55
55
  "files": [
56
56
  "dist"