@postalsys/email-ai-tools 1.1.1 → 1.1.3
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/lib/generate-summary.js +44 -4
- package/package.json +1 -1
package/lib/generate-summary.js
CHANGED
|
@@ -31,7 +31,7 @@ Instructions:
|
|
|
31
31
|
- Do not include message signatures in the extracted reply text
|
|
32
32
|
- If the email text mentions events, return these events as separate event objects in an "events" array
|
|
33
33
|
- In the event object include the following properties
|
|
34
|
-
- "description" property that describes the event
|
|
34
|
+
- "description" property that describes the event in English
|
|
35
35
|
- "location" property that defines the expected location of the event
|
|
36
36
|
- "startTime" property that includes a timestamp without a timezone for the start of the event
|
|
37
37
|
- "endTime" property that includes a timestamp without timezone for the expected end of the event if there is high confidence for the value
|
|
@@ -43,7 +43,7 @@ Instructions:
|
|
|
43
43
|
- "general" describes a generic event, like a fair or a competition
|
|
44
44
|
- If the email text mentions actions that the recipient must take, return these actions as separate action objects in an "actions" array
|
|
45
45
|
- In the action object, include the following properties
|
|
46
|
-
- "description" property that summarises the action
|
|
46
|
+
- "description" property that summarises the action in English
|
|
47
47
|
- "dueDate" property that includes a timestamp without a timezone for the due date of the action
|
|
48
48
|
- Do not include the event in the "events" array if the confidence for it being an event is low
|
|
49
49
|
- Generate a security analysis of the email and store the security analysis in "riskAssessment" property as an object value.
|
|
@@ -136,7 +136,8 @@ async function generateSummary(message, apiToken, opts) {
|
|
|
136
136
|
promptText = promptText.substr(0, MAX_ALLOWED_TEXT_LENGTH);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
// eslint-disable-next-line no-constant-condition
|
|
140
|
+
while (true) {
|
|
140
141
|
content.text = promptText;
|
|
141
142
|
prompt = `${USER_PROMPT}
|
|
142
143
|
|
|
@@ -202,7 +203,6 @@ ${JSON.stringify(content)}`;
|
|
|
202
203
|
});
|
|
203
204
|
|
|
204
205
|
data = await res.json();
|
|
205
|
-
|
|
206
206
|
if (!res.ok) {
|
|
207
207
|
if (res.status === 429 && ++retries < 5) {
|
|
208
208
|
// try again
|
|
@@ -255,6 +255,7 @@ ${JSON.stringify(content)}`;
|
|
|
255
255
|
if (typeof values.shouldReply !== 'undefined' && typeof values.shouldReply !== 'boolean') {
|
|
256
256
|
delete values.shouldReply;
|
|
257
257
|
}
|
|
258
|
+
|
|
258
259
|
if (values && values.events) {
|
|
259
260
|
values.events = []
|
|
260
261
|
.concat(values.events || [])
|
|
@@ -262,6 +263,20 @@ ${JSON.stringify(content)}`;
|
|
|
262
263
|
.map(event => {
|
|
263
264
|
let result = {};
|
|
264
265
|
for (let key of Object.keys(event)) {
|
|
266
|
+
switch (key) {
|
|
267
|
+
case 'startTime':
|
|
268
|
+
case 'endTime':
|
|
269
|
+
{
|
|
270
|
+
if (event[key]) {
|
|
271
|
+
let parsedDate = new Date(event[key]);
|
|
272
|
+
if (parsedDate.toString() === 'Invalid Date') {
|
|
273
|
+
event[key] = '';
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
|
|
265
280
|
if (event[key] !== '' && event[key] !== null) {
|
|
266
281
|
result[key] = event[key];
|
|
267
282
|
}
|
|
@@ -269,6 +284,31 @@ ${JSON.stringify(content)}`;
|
|
|
269
284
|
return result;
|
|
270
285
|
});
|
|
271
286
|
}
|
|
287
|
+
|
|
288
|
+
if (values && values.actions) {
|
|
289
|
+
values.actions = [].concat(values.actions || []).map(action => {
|
|
290
|
+
let result = {};
|
|
291
|
+
for (let key of Object.keys(action)) {
|
|
292
|
+
switch (key) {
|
|
293
|
+
case 'dueDate':
|
|
294
|
+
{
|
|
295
|
+
if (action[key]) {
|
|
296
|
+
let parsedDate = new Date(action[key]);
|
|
297
|
+
if (parsedDate.toString() === 'Invalid Date') {
|
|
298
|
+
action[key] = '';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (action[key] !== '' && action[key] !== null) {
|
|
306
|
+
result[key] = action[key];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
272
312
|
} catch (err) {
|
|
273
313
|
let error = new Error('Failed to parse output from OpenAI API');
|
|
274
314
|
error.textContent = output;
|