@hestia-earth/api 0.28.13 → 0.28.14

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.
@@ -52,8 +52,10 @@ const validateConfig = (config) => {
52
52
  isStringRecord(config) || invalid('config must be an object');
53
53
  validateEngine('engine', config.engine);
54
54
  validateEngine('fixEngine', config.fixEngine);
55
+ validateEngine('narrativeProvider', config.narrativeProvider);
55
56
  validateOptionalString('model', config.model);
56
57
  validateOptionalString('fixModel', config.fixModel);
58
+ validateOptionalString('narrativeModel', config.narrativeModel);
57
59
  validateReviewerList('reviewers', config.reviewers);
58
60
  validateReviewerList('pdfConversion', config.pdfConversion);
59
61
  validateApiKeys(config.apiKeys);
@@ -169,6 +169,7 @@ export class File extends BaseFile {
169
169
  nbCycles;
170
170
  nbImpactAssessments;
171
171
  hestiaDataPath;
172
+ report;
172
173
  }
173
174
  const fileNoExtSearch = (key, ...parts) => {
174
175
  const [filepathNoExt] = parts.filter(Boolean).join('/').split('.');
@@ -2,7 +2,6 @@ const reportOptionKeys = [
2
2
  'product',
3
3
  'limit',
4
4
  'feedback',
5
- 'narrativeModel',
6
5
  'format',
7
6
  'noNarrative',
8
7
  'noBenchmark',
@@ -11,3 +10,14 @@ const reportOptionKeys = [
11
10
  'refetch'
12
11
  ];
13
12
  export const reportOptionsFromBody = (body = {}) => reportOptionKeys.reduce((acc, key) => (body[key] === undefined ? acc : { ...acc, [key]: body[key] }), {});
13
+ export const reportNarrativeFromPreset = ({ narrativeProvider, narrativeModel } = {}) => ({
14
+ ...(narrativeProvider ? { narrativeProvider } : {}),
15
+ ...(narrativeModel ? { narrativeModel } : {})
16
+ });
17
+ export const REPORT_FORMATS = ['pdf', 'docx', 'html'];
18
+ export const REPORT_SUPPLEMENTARY_FILENAME = 'report-supplementary.xlsx';
19
+ const reportMainRegExp = new RegExp(`^report\\.(${REPORT_FORMATS.join('|')})$`);
20
+ export const reportKeyPrefix = (subjectId) => `${subjectId}/`;
21
+ const reportFilename = (key) => key.split('/').pop() || '';
22
+ export const reportMainFormat = (key) => reportFilename(key).match(reportMainRegExp)?.[1];
23
+ export const isReportSupplementary = (key) => reportFilename(key) === REPORT_SUPPLEMENTARY_FILENAME;
@@ -27,6 +27,8 @@ export interface LlmPresetConfig {
27
27
  pdfConversion?: LlmReviewer[];
28
28
  fixEngine?: LlmEngine;
29
29
  fixModel?: string;
30
+ narrativeProvider?: LlmEngine;
31
+ narrativeModel?: string;
30
32
  apiKeys?: Partial<Record<LlmApiKey, string>>;
31
33
  }
32
34
  export interface LlmPreset {
@@ -56,8 +56,10 @@ const validateConfig = (config) => {
56
56
  isStringRecord(config) || invalid('config must be an object');
57
57
  validateEngine('engine', config.engine);
58
58
  validateEngine('fixEngine', config.fixEngine);
59
+ validateEngine('narrativeProvider', config.narrativeProvider);
59
60
  validateOptionalString('model', config.model);
60
61
  validateOptionalString('fixModel', config.fixModel);
62
+ validateOptionalString('narrativeModel', config.narrativeModel);
61
63
  validateReviewerList('reviewers', config.reviewers);
62
64
  validateReviewerList('pdfConversion', config.pdfConversion);
63
65
  validateApiKeys(config.apiKeys);
@@ -1,6 +1,7 @@
1
1
  import { ISourceJSONLD, NodeType } from '@hestia-earth/schema';
2
2
  import { BaseModel } from '../../db/model.base';
3
3
  import { User, UserRole } from '../../users/model/model';
4
+ import { ReportFiles } from '../../reports/model';
4
5
  export declare const mb = 1048576;
5
6
  export declare const sizeInMb: (size: number) => number;
6
7
  export declare const maxFileSizeMb = 100;
@@ -162,6 +163,7 @@ export declare class File extends BaseFile {
162
163
  readonly nbCycles?: number;
163
164
  readonly nbImpactAssessments?: number;
164
165
  readonly hestiaDataPath?: string;
166
+ readonly report?: ReportFiles;
165
167
  }
166
168
  export declare const filenameSearch: (...parts: string[]) => {
167
169
  [x: string]: {
@@ -176,6 +176,7 @@ class File extends BaseFile {
176
176
  nbCycles;
177
177
  nbImpactAssessments;
178
178
  hestiaDataPath;
179
+ report;
179
180
  }
180
181
  exports.File = File;
181
182
  const fileNoExtSearch = (key, ...parts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/api",
3
- "version": "0.28.13",
3
+ "version": "0.28.14",
4
4
  "description": "Hestia API definitions",
5
5
  "main": "models.js",
6
6
  "module": "esm/models.js",
@@ -7,7 +7,6 @@ export interface ReportOptions {
7
7
  product?: string;
8
8
  limit?: number;
9
9
  feedback?: string;
10
- narrativeModel?: string;
11
10
  format?: string | string[];
12
11
  noNarrative?: boolean;
13
12
  noBenchmark?: boolean;
@@ -15,10 +14,27 @@ export interface ReportOptions {
15
14
  radar?: boolean;
16
15
  refetch?: boolean;
17
16
  }
18
- export interface ReportParams extends ReportOptions {
17
+ export interface ReportNarrative {
18
+ narrativeProvider?: string;
19
+ narrativeModel?: string;
20
+ }
21
+ export interface ReportParams extends ReportOptions, ReportNarrative {
19
22
  fileId?: string;
20
23
  sourceId?: string;
21
24
  nodes?: ReportNode[];
22
25
  dataVersion?: string;
23
26
  }
24
27
  export declare const reportOptionsFromBody: (body?: ReportOptions) => ReportOptions;
28
+ export declare const reportNarrativeFromPreset: ({ narrativeProvider, narrativeModel }?: ReportNarrative) => ReportNarrative;
29
+ export declare const REPORT_FORMATS: readonly ["pdf", "docx", "html"];
30
+ export type ReportFormat = (typeof REPORT_FORMATS)[number];
31
+ export declare const REPORT_SUPPLEMENTARY_FILENAME = "report-supplementary.xlsx";
32
+ export declare const reportKeyPrefix: (subjectId: string) => string;
33
+ export declare const reportMainFormat: (key: string) => ReportFormat | undefined;
34
+ export declare const isReportSupplementary: (key: string) => boolean;
35
+ export interface ReportFiles {
36
+ reportPaths: {
37
+ [format in ReportFormat]?: string;
38
+ };
39
+ supplementaryPath?: string;
40
+ }
package/reports/model.js CHANGED
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reportOptionsFromBody = void 0;
3
+ exports.isReportSupplementary = exports.reportMainFormat = exports.reportKeyPrefix = exports.REPORT_SUPPLEMENTARY_FILENAME = exports.REPORT_FORMATS = exports.reportNarrativeFromPreset = exports.reportOptionsFromBody = void 0;
4
4
  const reportOptionKeys = [
5
5
  'product',
6
6
  'limit',
7
7
  'feedback',
8
- 'narrativeModel',
9
8
  'format',
10
9
  'noNarrative',
11
10
  'noBenchmark',
@@ -15,3 +14,18 @@ const reportOptionKeys = [
15
14
  ];
16
15
  const reportOptionsFromBody = (body = {}) => reportOptionKeys.reduce((acc, key) => (body[key] === undefined ? acc : { ...acc, [key]: body[key] }), {});
17
16
  exports.reportOptionsFromBody = reportOptionsFromBody;
17
+ const reportNarrativeFromPreset = ({ narrativeProvider, narrativeModel } = {}) => ({
18
+ ...(narrativeProvider ? { narrativeProvider } : {}),
19
+ ...(narrativeModel ? { narrativeModel } : {})
20
+ });
21
+ exports.reportNarrativeFromPreset = reportNarrativeFromPreset;
22
+ exports.REPORT_FORMATS = ['pdf', 'docx', 'html'];
23
+ exports.REPORT_SUPPLEMENTARY_FILENAME = 'report-supplementary.xlsx';
24
+ const reportMainRegExp = new RegExp(`^report\\.(${exports.REPORT_FORMATS.join('|')})$`);
25
+ const reportKeyPrefix = (subjectId) => `${subjectId}/`;
26
+ exports.reportKeyPrefix = reportKeyPrefix;
27
+ const reportFilename = (key) => key.split('/').pop() || '';
28
+ const reportMainFormat = (key) => reportFilename(key).match(reportMainRegExp)?.[1];
29
+ exports.reportMainFormat = reportMainFormat;
30
+ const isReportSupplementary = (key) => reportFilename(key) === exports.REPORT_SUPPLEMENTARY_FILENAME;
31
+ exports.isReportSupplementary = isReportSupplementary;