@adobe/spacecat-shared-utils 1.27.0 → 1.28.1
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 +14 -0
- package/package.json +1 -1
- package/src/helpers.js +21 -0
- package/src/index.d.ts +13 -0
- package/src/index.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-utils-v1.28.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.28.0...@adobe/spacecat-shared-utils-v1.28.1) (2025-01-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* getPrompt and replacePlaceholders not properly exported ([#553](https://github.com/adobe/spacecat-shared/issues/553)) ([236839c](https://github.com/adobe/spacecat-shared/commit/236839ca9785f77576889e768cb1707c49bb1fb4))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-utils-v1.28.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.27.0...@adobe/spacecat-shared-utils-v1.28.0) (2025-01-21)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* introduce get prompt from static files ([#552](https://github.com/adobe/spacecat-shared/issues/552)) ([0ae7392](https://github.com/adobe/spacecat-shared/commit/0ae739243722812c6b895fe5d843424d23b7f29c))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-utils-v1.27.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.26.6...@adobe/spacecat-shared-utils-v1.27.0) (2025-01-21)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/helpers.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { Parser } from '@json2csv/plainjs';
|
|
14
14
|
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
|
15
|
+
import { promises as fs } from 'fs';
|
|
15
16
|
import { isString } from './functions.js';
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -110,3 +111,23 @@ export function replacePlaceholders(content, placeholders) {
|
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
113
|
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Reads the content of a prompt file asynchronously and replaces any placeholders
|
|
117
|
+
* with the corresponding values. Logs the error and returns null in case of an error.
|
|
118
|
+
*
|
|
119
|
+
* @param {Object} placeholders - A JSON object containing values to replace in the prompt content.
|
|
120
|
+
* @param {String} filename - The filename of the prompt file.
|
|
121
|
+
* @param {Object} log - The logger
|
|
122
|
+
* @returns {Promise<string|null>} - A promise that resolves to a string with the prompt content,
|
|
123
|
+
* or null if an error occurs.
|
|
124
|
+
*/
|
|
125
|
+
export async function getPrompt(placeholders, filename, log = console) {
|
|
126
|
+
try {
|
|
127
|
+
const promptContent = await fs.readFile(`./static/prompts/${filename}.prompt`, { encoding: 'utf8' });
|
|
128
|
+
return replacePlaceholders(promptContent, placeholders);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
log.error('Error reading prompt file:', error.message);
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -152,6 +152,19 @@ declare function generateCSVFile(data: object[]): Buffer;
|
|
|
152
152
|
*/
|
|
153
153
|
declare function replacePlaceholders(content: string, placeholders: object): string;
|
|
154
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Reads the content of a prompt file asynchronously and replaces any placeholders
|
|
157
|
+
* with the corresponding values. Logs the error and returns null in case of an error.
|
|
158
|
+
*
|
|
159
|
+
* @param {Object} placeholders - A JSON object containing values to replace in the prompt content.
|
|
160
|
+
* @param {String} filename - The filename of the prompt file.
|
|
161
|
+
* @param {Object} log - The logger
|
|
162
|
+
* @returns {Promise<string|null>} - A promise that resolves to a string with the prompt content,
|
|
163
|
+
* or null if an error occurs.
|
|
164
|
+
*/
|
|
165
|
+
declare function getPrompt(placeholders: object, filename: string, log: object):
|
|
166
|
+
Promise<string|null>;
|
|
167
|
+
|
|
155
168
|
/**
|
|
156
169
|
* Retrieves stored metrics from S3.
|
|
157
170
|
* @param config - Configuration object
|